IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Mozilla JavaScript question
Must have brain lock because I can't figure out why the access to the radio button isn't working in Mozilla 1.5:

<html>\n<head><title>Test Radio</title></head>\n<body>\n<form id='MyForm'>\n    <input type='radio' name='MyRadio' id='MyRadio' value='Y' checked  />Yes <br />\n    <input type='radio' name='MyRadio' id='MyRadio' value='N'          />No  <br />\n</form>\n\n<script language='JavaScript' type='text/javascript'>\n   if (document.getElementById("MyForm").MyRadio[0].checked) {\n      alert("hello");\n   }\n</script>\n</body>\n</html>\n\n<!--\nError: document.getElementById("MyForm").MyRadio[0] has no properties\nSource File: [link|http://localhost/test.html|http://localhost/test.html]\nLine: 10\n-->\n

New Works on Mozilla 1.4
I'm not sure why one would not just name things normally, but the above seems to work here.

Cheers,
Ben
"good ideas and bad code build communities, the other three combinations do not"
- [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
New Names were changed to protect the guilty
Worked under Mozilla 1.3 as well. 1.5 seems to be a different story. Code involved was distilled down to illustrate the problem.

Ok, so I see the source of the problem stems from the fact that the input name and id have the same name. If I rename either one (but leave the other the same), it will work in 1.5 as well. Not sure why the behavior changed - whether it's by design or accident.
New Bug of some sort
After playing around for a while I discovered that it is some sort of bug. The following code does work in 1.5 on Linux.
<html>\n<head><title>Test Radio</title></head>\n<body>\n<form id='MyForm'>\n    <input name='MyRadio' id='MyRadio' type='radio' value='Y' checked  />Yes <br />\n    <input name='MyRadio' id='MyRadio' type='radio' value='N'          />No  <br />\n</form>\n\n<script language='JavaScript' type='text/javascript'>\n   if (document.getElementById("MyForm").MyRadio[0].checked) {\n      alert("hello");\n   }\n</script>\n</body>\n</html>

The only difference being I put the type after the name and ID.

Seems to be this one [link|http://bugzilla.mozilla.org/show_bug.cgi?id=183940|Bugzilla].

Jay
New That looks like the one. Thanks.
Thought I was going out of my mind on this one - began to question whether I missed the whole DOM thing. :-)
New Your ID fields aren't unique.
On the controls, that is. Although you're not using them, Moz's DOM engine may still be getting flummoxxed by their non-uniqueness.

Wade.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

     Mozilla JavaScript question - (ChrisR) - (5)
         Works on Mozilla 1.4 - (ben_tilly) - (1)
             Names were changed to protect the guilty - (ChrisR)
         Bug of some sort - (JayMehaffey) - (1)
             That looks like the one. Thanks. - (ChrisR)
         Your ID fields aren't unique. - (static)

Remember, rank times IQ is a constant.
62 ms