Thomas said:
DU wrote:
Lasse said:
Lasse Reichstein Nielsen wrote:
The appropriate and standards[1] sanctioned way to access a form
control is:
document.forms['myform'].elements['address']
document.forms[0].elements.namedItem("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)
We understand each other.
I am afraid you did not understand.
I was merely mentioning another W3C-web-standards way of accessing a
form control. Lasse's initial answer somewhat suggested there was only 1
way.
It should have been saying "... there is not just one appropriate
way...". Somehow I forgot to write the "not" word. My initial reply was
clearly suggesting there is more than 1 W3C web standard way to access a
form control.
But you are wrong, read again. There are exactly four possibilities
of accessing a form element in a standards-compliant way
Exactly four? There are other web standard compliant ways to access a
form element. You can give a form element an id attribute and then
access it with getElementById method. Roughly 96% (and still growing) of
all browsers in use out there support that method. NN 3.x, NN 4.x, IE
3.x and IE 4.x do not support getElementById though.
: The
namedItem(...) method, the index operator with a string operand, the
item(...) method and the index operator with a numeric operand. The
index operator (`[...]'), however is also downwards compatible as the
`document.forms' and `elements' collections or arrays were already part
of "DOM Level 0"
DOM Level 0 is not a technical recommendation from the W3C. Never was.
from IE 3.0 and NN 3.0 on while the namedItem(...)
and item(...) methods were not.
Are you saying people should not be using namedItem or item because IE
3.0 and NN 3.0 do not support these methods? Is that what you are
actually saying? IE 3.0 and NN 3.0 were designed and developed 8 years
ago, you know.
And what about other methods? NN 3.x, IE 3.x, NN 4.x and IE 4.x do not
support about every possible DOM 1 methods (including those which
generates HTMLCollections, nodeLists and NamedNodeMaps) and attributes
listed in W3C TRs. Would you go as far as saying we should not use any
of them because NN 3.x, IE 3.x, NN 4.x and IE 4.x do not support them as
well? and so forth for CSS1 properties, HTML 4 elements, attributes,
etc. that are either not supported or not working well in NN 3.x, NN
4.x, IE 3.x and IE 4.x?
So the saner way is using the index
operator as Lasse suggested.
PointedEars
Lasse's initial reply did not make use of the index with an numeric
operand; I was the first to mention and use it in this thread.
DU