I want to determine if a radio button has been selected. FF and Safari evaluate this differently.
for (i = 0; i < document.forms[0].RadioButtonName.length; i++)
{
if (document.forms[0].ShirtSize[i].checked)
{
alert('true');
}
else
{
alert('false');
}
}
Firefox will loop through once for each of the 3 buttons (in this case) and return false or true, consistent with what's been selected in the form. Safari returns false regardless of which is selected.
You're wording is confusing. The function above wouldn't RETURN any value, it would just make an alert for every single radio button in the form which would either be true or false.
I purposely inserted alert() boxes to see how the code was being evaluated at each step. FF displays true or false as expected, based upon which value was selected. Safari on the other hand, displays false for all buttons regardless of which is selected. It's as though Safari doesn't recognize the .checked property.
Ok. Based on aj_nsc's post, I tried a different approach. But now the script doesn't run in any browser, indicating a syntax error I'm sure. But can't find it. Here's the code:
function verifyOrder()
{
if (CheckRadioButtons('Group1') &&
CheckRadioButtons('Group2') &&
CheckRadioButtons('Group3'))
document.forms[0].submit();
else
alert ( "Oops! Don't forget to make a selection for each group!");
function verifyOrder()
{
if (CheckRadioButtons('RBGroup1') &&
CheckRadioButtons('RBGroup2') &&
CheckRadioButtons('RBGroup3'))
document.forms[0].submit();
else
alert ( "Oops! Don't forget to make a selection for each group!");
}
Maybe the problem is in my form? The radio buttons are using a custom image and script, in place of the default control supplied by the browser, so the <input> tag is set to display:none, and is placed within a <label> tag, along with the replacement image to enable the replacement image (checkbox_off.gif) to act on behalf of the <input> control. I'm also wrapping checkbox_off.gif in an anchor, so to call a script to swap out the "off" image for the "on" when clicked (that code works perfectly in all browsers).
Bookmarks