warn user if all checkboxes are unchecked

后端 未结 5 1649
借酒劲吻你
借酒劲吻你 2021-02-09 00:04

I have a form with a series of checkboxes. I want to warn the user, after they hit submit, if ALL of the checkboxes are unchecked. I\'m using the following code to report all

5条回答
  •  粉色の甜心
    2021-02-09 00:24

    You can use jQuery object's length property:

    $("#set_pref_submit").click(function() {
        var legchecked = $('input[id^=leg_rider]:checked').length;
        if (legchecked){ alert("no riders")};
    });
    

提交回复
热议问题