...

View Full Version : radio index question



Tails
01-16-2003, 09: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?

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

whammy
01-17-2003, 12:54 AM
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?

Perhaps...

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

:confused:

What exactly are you trying to do?

Tails
01-17-2003, 09: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
</FORM>

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>
</FORM>

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?

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

if you have
radio
radio
check
radio
check
check

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum