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:
0 -> Form ONE
1 -> Form TWO
ONE -> Form ONE
TWO -> Form TWO
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:
0 -> First form
1 -> Second form
ONE -> Form ONE
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.
Although the FormArray is a collection, the MSIE 5.0 browser on the Macintosh will crash if you try to use the item() method on it.
Be careful to avoid naming forms identically if you have more than one in a document. You still get the correct number of Form objects but accessing them via the FormArray may become problematic if you use the name attributes to locate them associatively.
See also: | Collection object, Document.forms[] |
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
length | 1.0 ![]() | 3.0 ![]() | 2.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Method | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
item() | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
Prev | Home | Next |
Formal Parameter List | Up | FormArray.item() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |