warn user if all checkboxes are unchecked

后端 未结 5 1652
借酒劲吻你
借酒劲吻你 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:36

    On the line

    if (!legchecked){ alert("no riders")};
    

    You're actually checking the existence of the object, not if it's empty. Since you're using jQuery, you could use the .isEmptyObject() function to check if the object is empty.

    if($.isEmptyObject(legchecked)) {alert ("no riders")};
    

提交回复
热议问题