Advertisement
lessientelrunya

formvalidation

Jul 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.42 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4.     <head>
  5.         <title>form1</title>
  6.     </head>
  7.     <body>
  8.         <form action="/register" id="registration" method="get">
  9.             <input name="email" placeholder="Email" type="text"/>
  10.             <input name="password" placeholder="Password" type="password"/>
  11.             <input name="confirmation" placeholder="Password (again)" type="password"/>
  12.             <input name="agreement" type="checkbox"/> I agree
  13.             <input type="submit" value="Register"/>
  14.         </form>
  15.         <script>
  16.  
  17.             var form = document.getElementById('registration');
  18.             form.onsubmit = function() {
  19.  
  20.                 if (form.email.value == '')
  21.                 {
  22.                     alert('missing email');
  23.                     return false;
  24.                 }
  25.                 else if (form.password.value == '')
  26.                 {
  27.                     alert('missing password');
  28.                     return false;
  29.                 }
  30.                 else if (form.password.value != form.confirmation.value)
  31.                 {
  32.                     alert('passwords don\'t match');
  33.                     return false;
  34.                 }
  35.                 else if (!form.agreement.checked)
  36.                 {
  37.                     alert('checkbox unchecked');
  38.                     return false;
  39.                 }
  40.                 return true;
  41.  
  42.             };
  43.  
  44.         </script>
  45.    </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement