Advertisement
victorumeh

my first form validation code

Feb 25th, 2022
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.89 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <title>Document</title>
  5.     <script type="text/javascript">
  6.       function validate() {
  7.         let x = document.forms.myForm.Email.value;
  8.         if (x == "") {
  9.           alert("Please enter your Email ID");
  10.           document.myForm.Email.focus();
  11.           return false;
  12.         } else if (document.myForm.password.value == "") {
  13.           alert("Please enter your Password");
  14.           document.myForm.password.focus();
  15.           return false;
  16.         } else {
  17.           return true;
  18.         }
  19.       }
  20.     </script>
  21.   </head>
  22.   <body>
  23.     <form action="message.html" name="myForm" onsubmit="return validate()">
  24.       <input type="text" name="Email" placeholder="Email" /><br />
  25.       <input type="password" name="password" placeholder="password" /><br />
  26.       <button type="submit">Submit</button>
  27.     </form>
  28.   </body>
  29. </html>
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement