"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:vf**********@hotpop.com...
<snip>
Most browsers accept some shorthands for both the forms and
elements collections:
document.formName.elemName
or (notably IE)
formName.elemName
(i.e., window.formName.elemName)
None of these shorthands are part of the W3C DOM
specification, so it is safer to write write it all out.
<snip>
While non of these shorthand versions are specified, the HTML DOM level
2 specification does appear to allow a short hand of referring to the
element as a named property of the form object:-
FormObject['elemName']
- or -
FormObject.elemName
- as the spec describes the form element as <quote> The FORM element
encompasses behavior similar to a collection and an element. It provides
direct access to the contained form controls as well as the attributes
of the form element.</quote>.
I, like you, prefer to use the longer form and access via the elements
collection using:-
document.forms['formName'].elements['elName']
- for exactly the same reasons of code clarity (and universal browser
support), and if it will be a problem that that form resolves slightly
slower than a shortcut form then that can usually be overcome by caching
a reference to the elements collection and subsequently referring to
named elements relative to that.
var els = document.forms['formName'].elements;
for(var c = 0;c < 10000;c++){
els['elName'+c].value = ''; //clear 10000 consecutively named
//elements without resolving the
//form object or its elements
//collection for each.
}
Richard.