DU <dr*******@hotW IPETHISmail.com > writes:
Lasse Reichstein Nielsen wrote:
HTMLCollection can make use of the namedItem method to retrieve a node.
Yes, or normal property access, using the NAME of the collection element
is the property name.
The appropriate and standards[1] sanctioned way to access a form
control is:
document.forms['myform'].elements['address']
document.forms[0].elements.named Item("address")
is perfectly standard and works without a glitch in Mozilla 1.5, Opera
7.23, MSIE 6 for windows and K-meleon 0.8.
So is and does
document.forms['myform'].elements['address']
(ok, I haven't checked K-meleon, but it's Gecko-based)
Using forms[0] avoids the problem that Netscape 4 apparently has (not
recognizing the id attribute on forms). However, it makes the script
more fragile, since adding a form before the first will break the script.
I would rather put both the "id" and "name" attribute there (with the
same value).
"HTMLcollection " is defined in W3C DOM 2 HTML. The ECMAScript bindings
part of DOM 2 HTML says that using square bracket property access
notation is equivalent to using the namedItem method. Quote:
---
namedItem(name)
This function returns an object that implements the Node interface.
The name parameter is a String.
Note: This object can also be dereferenced using square bracket
notation (e.g. obj["foo"]). Dereferencing using a string index is
equivalent to invoking the namedItem function with that index.
---
(from <URL:http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>)
Since ECMAScript says that obj.foo is equivalent to obj["foo"] when
foo is valid identifier, using the dot notation for property access
should work as well.
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'