Checking jQuery checkbox

I am using jQuery code below to validate the form. Now everything works fine, but I would like the check box to use .validator , not its current alert , but when I add required="required" to the checkbox input fields, I get messages for all checkboxes, whereas I only need one .

 $("#request-form").validator({ message: '<div><em/></div>', position: 'top left', offset: [3, 40] }); $("#see").overlay({mask: '#999', fixed: false}).bind("onBeforeClose", function(e) { $(".error").hide(); }); $('#request-form').submit(function(){ if(!$('#request-form input[type="checkbox"]').is(':checked')){ alert("Please check at least one."); return false; } }); 

Hope this makes sense. Thank you in advance. S

+4
source share
1 answer

Here is the code that will work with the jQuery Validation Plugin . I am not sure if this will work with what you use, because I have never heard of it.

 $("#request-form").validate({ rules: { checkbox: { required: 'input[type="checkbox"]:checked', minlength: $('input[type="checkbox"]').length() } }, messages: { checkbox: "Please check at least one.", } }); 

NTN

+5
source

All Articles