Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Button Help please

Status
Not open for further replies.

hopper

Programmer
Dec 5, 2000
27
0
0
US
I'm sure this is an easy one, but I need some help.
I need to find out if any one radio button in a group has been checked where the number of radio buttons isn't known until run time. I was using

if (form.radio1[0].checked = true || form.radio1[1].checked = true...)

but now the number of radio buttons in radio1 is dynamic.

Any ideas?

Thanks,

Scott
 
for (i=0;i<document.formName.radio1.length;i++) {
if (!document.formName.radio1.checked)
{
// a checkbox is unchecked
break;
}
}
 
for (i=0;i<document.formName.radio1.length;i++) {
if (document.formName.radio1.checked)
{
// a checkbox is checked
break;
}
}
 
Using sjravee's idea, this is a function that will return true if any of the radio buttons is checked, and false if none of them are:

function checkradiobuttons(radioarray)
{
for (var ri=0;ri<radioarray.length;ri++)
{
if (radioarray[ri].checked==true) return true;
}
return false;
}


 
That's perfect!!!!

Thank you!

Scott
 
Hi !

Since form.radio1 is an ARRAY maybe U can use &quot;form.radio1.length&quot; to guess how many elements there are.

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top