Click to See Complete Forum and Search --> : Validate a radio button


AlishaMarie
04-18-2003, 02:58 PM
I've searched this site but cannot seem to find what I need. I have a form with a radio button on it and I need to validate it. When a user attempts to submit the form I need the validation to see if they made a selection and if not give them an error.

Here is what i have but it won't work...


if (f.NumLocations.checked = false)
{
alert ("Please Select the Number of Locations");
f.NumLocations.focus()
return false;
}

...Please advise. It gives me a "False undefined" error.

khalidali63
04-18-2003, 03:20 PM
I amsure you have multiple radio buttons and allof them hs the same name,that creates an array of radio buttons with that name,you have to loop through the radio button array and check of which button is checked.

AlishaMarie
04-18-2003, 03:24 PM
Do I have to do this although I don't care which one is selected? I just care that a selection has been made. Also, I'm developing in Lotus Notes and using JavaScript for the validation only. The field that I'm checking is a "notes" created field.

DrDaMour
04-18-2003, 03:29 PM
the comparison operator is ==

i hope you're not using =, as taht always returns true

if (f.NumLocations.checked = false)

AlishaMarie
04-18-2003, 03:38 PM
Yup. I tried that too...


if (f.NumLocations.checked == false)

DrDaMour
04-18-2003, 03:42 PM
and yes you have to go through all of htem, because the array isn't considered checked, just one of the radio buttons are. So what you're checking really ins't an object, but


for(var i = 0; i < f.NumLocations.length; i++){

(f.NumLocations[0].checked == true)
return true;

}

return false;


shoudl work, if you labels are right