gitlez

YA: Simple Form Required Fields Check

Apr 3rd, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.08 KB | None | 0 0
  1. <!-- In Response to a Yahoo Answers Question -->
  2. <html>
  3.     <head>
  4.         <script type="text/javascript" language="Javascript">
  5.             function validateForm(){
  6.                 var theForm = document.forms["myForm"];
  7.                 var theReqFields = ['bizname','fullname'];
  8.                 var formPass = 0;
  9.                 for( var x in theReqFields){
  10.                     if(theForm[x].value.length === 0){
  11.                         formPass++;
  12.                     }
  13.                 }
  14.                 if(formPass === 0){
  15.                     return true;
  16.                 }else{
  17.                     alert('Some Required Fields Are Empty. Please Correct before continueing.');
  18.                     return false;
  19.                 }
  20.             }
  21.         </script>
  22.     </head>
  23. <body>
  24.     <form name="myForm" onsubmit="return validateForm();">
  25.         Biz Name: <input type="text" name="bizname"><br>
  26.         Full Name: <input type="text" name="fullname"><br>
  27.         Email: <input type="text" name="email"><br>
  28.         <input type="submit" value="Send">
  29.     </form>
  30. </body>
  31. </html>
Advertisement
Add Comment
Please, Sign In to add comment