DHTML Collections
DOM Level 1 Specification.
Retrieves a collection of all FORM objects in a document.
[ collForms = ] document.forms |
[ oObject = ] document.forms ( vIndex [ , iSubIndex ] ) |
collForms |
Reference to an array of elements contained by the object. |
oObject |
Reference to an individual item in the array of elements contained by the object. |
vIndex |
Required. Number or string specifying the element or collection to retrieve. If this parameter is a number, the method returns the element in the collection at the given position, where the first element has value 0, the second has 1, and so on. If this parameter is a string and there is more than one element with the name or id property equal to the string, the method returns a collection of matching elements. |
iSubIndex |
Optional. Position of an element to retrieve. This parameter is used when vIndex is a string. The method uses the string to construct a collection of all elements that have a name or id equal to the string and then retrieves from this collection the element at the position specified by iSubIndex. |
The forms collection returns an array, in source order, of all the FORM elements in the current document.
Thus, each FORM in a document can be referenced as:
document.forms [ formIndex ]
As the collection is zero-based, the first form is forms [ 0
] , the second is forms [ 1
] , and so on.
In addition, a form may also be referenced by its name, and in DOM-compliant browsers, by its id property.
document.formName
document [ 'formName' ]
document.getELementById ( 'formID' )
The below code returns a reference to the collection, in source order, of all forms in a document.
formsList = document.forms
document
elements