I have created this generic function to check if a value of a radio button field has been selected.
The code for a multiple option field is different to a single option field because field.length for a single option is 'undefined' and not '1' as would be expected so I have initially tested if field.length == null
function RadioOptionSelected(fldRadioToCheck)
{
//returns whether the user has made a choice in a radio button group
if (fldRadioToCheck.length == null) //only one option
{
if (fldRadioToCheck.checked)
{
return true;
}
else
{
return false;
}
}
else //multiple options
{
for (intRadioOption = 0; intRadioOption < fldRadioToCheck.length ; intRadioOption++)
{
if (fldRadioToCheck[intRadioOption].checked == '1')
{
return true;
}
}
return false;
}
}
This was first published in November 2001