[thelist] javascript: ensuring that at least one radio button is selected
joe
stowaway at uklinux.net
Wed Jun 9 14:51:36 CDT 2004
Joel D Canfield wrote:
>I have two dozen radio buttons, named 'PrimaryIssue', all with different
>IDs/values. In this case, a default choice doesn't make sense. How do I
>ensure that at least one choice has been made?
>
>I've tried checking the value of 'PrimaryIssue', but that dinna work. I
>hate listing each ID separately. Is 'PrimaryIssue' an array I have to
>loop through?
>
>thanks
>
>joel
>
>
hi joel
rather than use js, can't you just ensure one of them is selected by
adding 'checked' to the first radio button? or I guess that's what you
mean by 'default choice doesn't make sense'... otherwise you can loop
through the array:
myArray = document.forms['formName'].PrimaryIssue;
for (a = 0; a < myArray.length; a++)
{
if (myArray[a].checked)
{
myChecked = true;
}
}
if (!myChecked)
{
// do what you gotta do
}
joe
More information about the thelist
mailing list