开发者

You need to select at least one radio button / checkbox

开发者 https://www.devze.com 2022-12-10 23:51 出处:网络
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?

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)) {
    // …
}
0

精彩评论

暂无评论...
验证码 换一张
取 消