JavaScript » Document » forms

Syntax:
document.forms["formID" ]

This property is an array containing references to all the Form objects in the current document.

This property is an array containing references to all the Form objects in the current document. These references are stored in the array in the order in which they are defined in the source code. The "formID" argument is used to access items in the array and this can either be a string containing the form name as defined within the <FORM> tag in the HTML source, or an integer (with '0' being the first item in the array).

Examples

Code:
document.forms["formname1"]
document.forms["formname2"]
document.forms["formname3"]

document.forms[0]
document.forms[1]
document.forms[2]

document.formname1
document.formname2
document.formname3
Explanation:

All examples return the same results; the first uses the defined names of the forms and the second uses their reference number within the array. A separate property is assigned to the document object for each form, which means that the forms can be accessed as in the last example.