You need to select at least one radio button / checkbox
What would be the JavaScript code to check if the user has select开发者_运维问答ed at least one radio button, knowing that the radio buttons all have the same "name" attribute?
Same question for checkboxes.
I do not use any fancy javascript frameworks such as JQuery and others ...
function IsARadioButtonChecked ( radiogroup ) {
for (var i = 0; i < radiogroup.length; i++) {
if (radiogroup[i].checked) {
return true;
}
}
return false;
}
if (IsARadioButtonChecked(document.forms.myForm.elements.myRadioGroupName)) {
// …
}
精彩评论