In article <yS*********************@nnrp1.uunet.ca>, "Mathieu Gagnon"
<ma**@netc.net> writes:
If I try...
<form name="a"><input name="name"></form>
alert(document.forms[0].elements[1].name)
alert(document.forms[0].name)
The first alert gives "name", the second : "[object]".
What I need is "a" alerted without changing the name of the input.
The reason you are getting object is because you have a form input named "name"
and as such, instead of trying to access the form's name property, it is
accessing the field element named name, which is an object. Thats part of why
you should never name form inputs (or ids, or classes), the same as an HTML
attribute.
If you are going to try to access the name of a form that has an input named
name,
you may want to try renaming the input, programattically, and then renaming it
after getting the form name:
document.forms[0].elements["name"].name = "someThingElse";
alert(document.forms[0].name);
document.forms[0].elements["someThingElse"].name = "name"
Another alternative, if you are just dead set on having it named "name", is to
capitalize it "Name" and then it won't interfere.
HTH
--
Randy
All code posted is dependent upon the viewing browser
supporting the methods called, and Javascript being enabled.