SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Older browsers, form syntax
-
Jun 17, 2003, 14:51 #1
- Join Date
- Jul 2002
- Location
- Fort Lauderdale
- Posts
- 123
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Older browsers, form syntax
Can anyone tell me if code to access form elements is compatible with older browsers, particularly IE, NS, and AOL? I'm thinking about NS 4.5+, IE 4+, AOL 5+. Example:
f = document.forms['formName'].elements;
-
Jun 17, 2003, 15:20 #2
- Join Date
- May 2003
- Posts
- 1,843
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
These have nothing to do with browser object models - they're simply alternative ways of referencing any browser object:
document.forms['formName'].elements;
document.forms.formName.elements;
Both reference the same object - the elements[] array of a form named 'formName' (imaginative), the first using hashtable referencing, the second, dot syntax. More here.
As for whether you need to include the [document.]forms[] collection in the reference, I'd say emphatically 'no' - but some people get exercised when you espouse any form of shortcut referencing so, take your pick. The same applies to document.image_name, document.form_name.element_name, Select[n] (no options[] reference) and so on. These all work in the v.4+ browsers mentioned.::: certified wild guess :::
-
Jun 17, 2003, 15:29 #3
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I actually prefer to use the hashtable references. Sometimes, forms and images aren't properly exposed as document properties (in some browsers) - and an XHTML-compatible form (one without a name attribute) won't register either. Using the collections removes all ambiguity.
Bookmarks