What I want is:
if(document.forms[0].elements[0][1].checked)
OR
if(document.forms[0].elements[0].[1].checked)
What works is:
if(document.forms[0].rad[1].checked)
Given:
<h3>Who's Bill?</h3>
<input type="radio" value="0" name="rad">Bill Clinton
<input type="radio" value="1" name="rad">Bill Gates
Well, your second preferred option is simply syntactically wrong. It won’t work in any situation, as it defies the rules of the language.
Your first preferred approach is not unreasonable, but consider that what you’re asking for is a specific element. Namely, the first element in the form. That element is a SINGLE radio button, not a group of them, so, as much as that syntax might be your preference, it doesn’t actually follow what you’re looking at in the code.
The way it works is that the form gets an array object named after the radio group name, and that array’s children are populated in the order in which your radio buttons actually turn up.
You can also access them as
document.forms[0].elements["rad"][0];//(1, 2… etc)Which may feel nicer to you? I don’t know… I’m not sure what you’re basing your preferred approach on, so, it’s hard to say if this would appeal to you more.