next up previous
Next: The Browser (navigator) Object Up: Objects in JavaScript Previous: Some Common window Methods

The Form Object

Two aspects of the form can be manipulated though JavaScript:

Form Elements:

This example shows a form and a function which reads the properties of the form elements:

<html>
<head>
  <script language="javascript">
    function validate() {
       var method = document.forms[0].method;
       var action = document.forms[0].action;
       var value = document.forms[0].elements[0].value;

       if(value != "David"){
         document.forms[0].reset();
       }
     else {
        alert("Hi David!!");
    }
   }
  </script>
</head>
<body>
  <form method="post">
    <input type="text" name="user" size=32>
    <input type="submit" value="Press Me!"
      onClick="validate()">
   </form>
</body>
</html>

The main points of this program are:

Further examples on data validation later.


next up previous
Next: The Browser (navigator) Object Up: Objects in JavaScript Previous: Some Common window Methods
Dave Marshall
9/28/2001