Advertisement
lalatino

html5 form validation example

Jul 8th, 2012
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.04 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en-US">
  3. <head>
  4. <title>http://stackoverflow.com/questions/11381369/html5-required-and-jquery-submit</title>
  5. <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
  6. <script type="text/javascript">
  7. <!--
  8.    function validateForm(form) {
  9.      if (form.username.value=='') {
  10.        alert('Username missing');
  11.        return false;
  12.      }
  13.      return true;
  14.    }
  15. //-->
  16. </script>
  17. </head>
  18. <body>
  19.  
  20. <form action="index.php" name="loginform" method="post" onsubmit="if (!validateForm(this)) event.preventDefault();">
  21.       <input name="username" placeholder="username" required="required" type="text" />
  22.       <a href="" onclick="event.preventDefault(); $(document.forms.loginform).submit();">Login1</a>
  23.       <a style="cursor:pointer;" onclick="$(document.forms.loginform).submit();">Login2</a>
  24.       <input name="send" type="submit" value="Login3" />
  25.       <input name="send" type="button" value="Login4" onclick="$(document.forms.loginform).submit();" />
  26. </form>
  27.  
  28. </body>
  29. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement