HTML and CSS Reference
In-Depth Information
window
document
forms[0] forms[1] forms[2]
Figure 11.11 The JavaScript forms[] array parallels the HTML form elements.
If you name the form with the name attribute of the HTML <form> tag, you can use
that name to reference the JavaScript forms object. Rather than saying document.forms[0]
or document.forms[1] , you can reference the form by its name. For example, if the first
HTML form is named myform1 , the corresponding JavaScript object, document.forms[0] ,
can now be referenced as document.myform1 . Even better, you can use the name of the
form as the index in an associative array, document.forms[“myform1”] where the name of
the form is the index value rather than a number.
The elements [] Array. HTML forms contain input devices like buttons and text-
boxes, also called fields. Similarly, the JavaScript form object consists of a property called
elements . This is a JavaScript array that parallels all of the HTML fields within the form.
Each of the input types in the elements[] array is also an object in its own right. See
Figure 11.12.
window
document
forms[0]
forms[1]
elements[0] elements[1] elements[...]
elements[0] elements[1] elements[...]
Figure 11.12 How the elements [] array parallels the HTML input devices.
 
 
Search WWH ::




Custom Search