Checking Number Of Selected Checkboxes
I saw the is function in jQuery, and it returns me, for example, if any of the checkboxes are selected. I need to do a check for how many checkboxes had been selected by the user,
Solution 1:
To get the amount of checkboxes checked and bind to the submit button:
$("#yourButton").click(function(e){
var n = $("input:checked").length; //Checkbox count, may need refinedif(n<2) //using n from above.
{
e.preventDefault();
}
});
Working Example: http://jsfiddle.net/ZtTG2/
Solution 2:
$(".submitBtn").click(function(event) {
if ($(":checked").length < 2) {
event.preventDefault();
} else {
$('form').submit();
}
});
Post a Comment for "Checking Number Of Selected Checkboxes"