Thanks for the explanation. It's interesting to note that if you have
multiple tags on the page, if just one of them has either name=itme or
id=item and then you can no longer access any of the elements by
item(index). For example the following fails:
<html>
The DOCTYPE declaration is missing before this tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"
http://www.w3.org/TR/html4/loose.dtd">
(or declare another fitting document type, preferably HTML 4.01 Strict).
<input type="button" name="wow" value="wow">
<input type="button" name="wow2" value="wow2">
<input type="button" name="wow3" value="wow3">
<input type="button" name="wow4" value="wow4">
<input type="button" name="wow5" value="wow5">
<input type="button" name="item" value="My name is item">
<script>
The required `type' attribute is missing:
alert("hello");
//try to access wow2 by index - this fails
alert(document.getElementsByTagName("input").item(1));
alert("hello");
</script>
</html>
However, if you put those controls into a `form' element, you do not need
Document::getElementsByTagName() and the item() method (whereas you do not
need the latter anyway since as per ECMAScript Language Binding the bracket
property accessor with a number value as argument serves the purpose[*]:
document.getElementsByTagName("input")[1]
), but the backwards compatible
document.forms[...].elements[1]
(provided that the corresponding `input' element is the second control in
the form) or, since you gave it a name,
document.forms[...].elements["wow2"]
The `...' need to be replaced either by the zero-based index of the form,
or the `form' element's name. But then you seldom need to give a form a
name because of the `form' property of (HTML)Input(Element) objects.
Search the archives.
PointedEars
___________
[*] <URL:
http://w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>