Checking Elements on a Form : Form HTML : Form Control JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Form Control » Form HTML »

 

Checking Elements on a Form




<html>
<head>
<title>Online Registration</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
     function checkFields() {
          var num = document.form1.elements.length
          var validFlag = true
          for (var i=0; i<num; i++) {
               if ((document.form1.elements[i].value == null || document.form1.elements[i].value == ""&&
                  (typeof document.form1.elements[i!= 'submit' || typeof document.form1.elements[i!= 'reset')){
                    validFlag = false;
                    alert("The " + document.form1.elements[i].name + " field is blank.")
                    break ;
               }
          }
          return validFlag;
     }
// -->
</SCRIPT>
</head>
   
<body>
<form name="form1" method="POST" onSubmit="return checkFields()">
<p>Username:<br>
    <input type=text size=25 maxlength=256 name="Username">
    <br>
    Email address:
    <strong><br></strong>
    <input type=text size=25 maxlength=256 name="EmailAddress"></p>
    <input type=submit value="Register"
    <input type=reset value="Clear">
</form>

</body>
</html>

           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Form Control
» Form HTML