I have two radio buttons with the same name. Using JavaScript, how can I check to see if either button is in focus? Here is what I’ve done so far; it’s part of my form validation:
if (element.type == "radio") {
if (element.checked === true) break;
else error.push(element.name || element.id);
}
And if the array “error” has any content in it, I’ll know that a check box is not selected. But it will say “form validated” only if both radios are selected. But I only want to know if either one with the same name is selected. How do I do that?
It’s a radio button. Set one to be selected by default, and having both be unchecked will be impossible and won’t need validation.