FormArray object (Object/browser)

The FormArray object is a collection of objects referring to the Form objects for the current document.

Availability:

JavaScript - 1.0
JScript - 3.0
Internet Explorer - 4.0
Netscape - 2.0
JavaScript syntax:-myFormArray = myDocument.forms
Object properties:length
Object methods:item()

The array is constructed by taking the <FORM> tags in the document and building a unique Form object for each.

In MSIE, the FormArray is constructed by adding an element to the array for each Form object and setting its key to be the value of the NAME="..." HTML tag attribute. For two named <FORM> tags, there will be only two entries in the array.

In Netscape, the array is constructed a little differently. First, the Form objects are created as was the case with MSIE. Then they are added to the array and can be accessed numerically. The FormArray.length property is then set according to the number of Form objects in the array. Then, additional elements are added to the FormArray to correspond to the NAME="..." HTML tag attribute. If you have this in your document:

   <FORM NAME="ONE">
   ...
   <FORM NAME="TWO">
   ...

Then your FormArray will contain these entries:

However the length property will still only return the value 2.

If you make both <FORM> tags identical, with the same NAME value, like this:

   <FORM NAME="ONE">
   ...
   <FORM NAME="ONE">
   ...

Then, you will get this array:

The length value still reports 2 but if you enumerate the array contents in a for( ... in ... ) loop, you get three entries now instead of four.

Regardless of how you define the forms in MSIE, it will always have the correct number of elements in the FormArray but they might have the same name. You can still access them numerically though.

Warnings:

See also:Collection object, Document.forms[]

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
length1.0 1.03.0 3.02.0 2.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning , readonly

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
item() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-