Advertisement
coffeebeforecode

Web Sec Lab Assign 2 Q1

Aug 31st, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.39 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="utf-8">
  5.     <title>Input Unique</title>
  6.     <script type="text/javascript">
  7.         let arr = [];
  8.         function validateForm() {
  9.             let x = document.forms["enterUnique"]["inp"].value;
  10.            
  11.             if (x == "") {
  12.                 alert("No value entered");
  13.                 return false;
  14.             }
  15.             else {
  16.                 return true;
  17.             }
  18.         }
  19.         function checkUnique() {
  20.             let flag = validateForm();
  21.             if (flag == false){
  22.                 return false;
  23.             }
  24.             let x = document.forms["enterUnique"]["inp"].value;
  25.             if (arr.includes(x)){
  26.                 document.getElementById("ans").innerHTML = "Duplicate";
  27.                 alert("Duplicate");
  28.                 document.getElementById("Submit").disabled = true;
  29.             }
  30.             arr.push(x);
  31.             document.getElementById("array").innerHTML = arr.toString();
  32.             document.forms["enterUnique"]["inp"].value = "";
  33.             return false;
  34.         }
  35.     </script>
  36. </head>
  37. <body>
  38.     <div align="center">
  39.         <h1>Enter Unique Values Only</h1>  
  40.         <br>
  41.         <h3>BCI3001 Web Security</h3>
  42.         <h3>Lab Assignment 2, Q1</h3>
  43.         <h3>Name: Devansh Sehgal</h3>
  44.         <h3>Registration Number: 20BCE0410</h3>
  45.     </div>
  46.     <hr>
  47.     <div align="center">
  48.         <form name="enterUnique" onsubmit="return checkUnique()">
  49.             Input:
  50.             <input type="number" name="inp" id="inp">
  51.             <input type="Submit" name="submit" value="Submit" id="Submit">
  52.         </form>
  53.         <br>
  54.         <div id="ans">Unique</div>
  55.         <div id="array"></div>
  56.     </div>
  57. </body>
  58. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement