[thelist] JS alerts not working for input type=radio buttons
Hardacker, Andrew
Andrew.Hardacker at Compuware.com
Fri Feb 22 11:29:01 CST 2002
<snip>
Then, I wrote alerts for two <.input type="radio"> fields in the same form,
as follows:
if (theForm.demo.value == "")
{
alert("Please enter a value for the \"demo\" field.");
theForm.demo.focus();
return (false);
}
Problem: The alerts work fine for the text inputs but don't work at all for
the radio buttons.
Ideas as to what I'm overlooking here?
</snip>
Sharon,
To verify if a user has checked a radio button, examine its "checked"
property. The group of radio buttons with the same name is accessed as an
array (the first entry is indexed with 0).
if (!theForm.demo[0].checked && !theForm.demo[1].checked)
{
alert("Please click on one of them little round doo-hickeys.");
// You could set focus on the button you think the user is most likely to
click.
// This is helpful for users who hit Enter to "check" radio buttons.
theForm.demo[0].focus();
return false;
}
HTH
Andy
More information about the thelist
mailing list