Click to See Complete Forum and Search --> : Radio buttons


tripwater
01-22-2004, 04:15 PM
Is there a way for me to validate a group of radio buttons with the same name without a for loop?
I only want to see if any of them are checked, it does not matter which. Thanks

<form name=form1>
<input type=radio name=temp value=1>
<input type=radio name=temp value=2>
<input type=radio name=temp value=3>
</form>

IceMetalPunk
01-22-2004, 04:25 PM
Hi-
If there are only 3 inputs, as you show, you cuold do this:

if (document.form1.temp[0].checked || document.form1.temp[1].checked || document.form1.temp[2].checked) { alert("True"); }

However, that is very limited. Is there any particular reason that you do not want to use a for loop? It would require less typing if you did use one.

-IceMetalPunk

tripwater
01-22-2004, 04:51 PM
Well the amount of radios is dynamic.

The names are dynamic as well.


I have a billing form at the top of the page with current info so you can change it and submit or you can select from a list of past addresses that you have entered into the system.

These addresses are assigned in a php for loop that gives them a name based on the billingid.


I first check to see if any radios are checked by
if (!document.form.radio.checked)

which if I have more than one and check one this still evaluates as one of them is still not checked. I have an else to this which then validates the expiration date field and credit card code field of that radio button.

So it would make life easier if instead of looping through I could evaluated that none are checked or at least one is checked in my first if statement. If there is a element index check or something. I hope this is not too confusing.

Thanks