View Full Version : radio index question

01-16-2003, 08:29 PM
So if radio buttons have the same name and have to use form.name[x], what do I do if I want to use an index for the input too? alert(form[x][y].value) does not work. Any suggestions?

01-16-2003, 08:34 PM
why would your radio buttons have the same names in one form?

01-16-2003, 11:54 PM
Radio buttons SHOULD have the same name, they are used for a single response out of multiple choices (like a multiple choice quiz).

Not sure what you mean by "use an index for the input". Can you explain?


var radios = document.forms[0].yourradioname;
var radlen = radios.length;
for(var i = 0; i < radlength; i++) {


What exactly are you trying to do?

01-17-2003, 08:20 PM
Well lets say I have a form named G and several inputs.

<FORM name="G">
<INPUT type="checkbox" checked>Choice A<BR>
<INPUT type="checkbox">Choice B

I normally use in a script activated by a button to read the values of these checkboxes. Not by their names (not assigned), but their index. Such as

if (G[1].checked){alert("Choice B was selected")}

But then radio buttons need to use an index too.

<FORM name="G">
<INPUT type="radio" name="gre1">No<BR>
<INPUT type="radio" name="gre1">Yes<BR>

Well, I guess each input works independently by themselves in their indexes regardless of wheather G[0] and G[1] have the same name or not. So names can be indexed, but the form index of each input works alone the same way as checkboxes. Is this right so far?

01-17-2003, 08:56 PM
The index doesnt care what it refers to.. just use the index and it will work...

if you have

on you form indices 2,4,5 will be checks and 0,1,3 radios
doesnt matter of they are text boxes either..

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum