I am trying to disable all unchecked checkboxes when there are 5 checked checkboxes.
My code is not working here it is: http://jsfiddle.net/mtYtW/18/
My Jquery:
I guess you want to disable the rest of the check boxes once the checked checkboxes count gets more than 5.If that is the case try this:
$('table input[type="checkbox"]').click(function(){
var countchecked = $('table input[type="checkbox"]').filter(":checked").length;
if(countchecked > 4) {
$("table input:checkbox").not(":checked").attr("disabled", true);
} else {}
});
Working example: http://jsfiddle.net/mtYtW/30/
If you want to disable the checkboxes on the page load and verify if there are more than 5 checkboxes that are checked then try this:
$(function(){
var countchecked = $('table input[type="checkbox"]').filter(":checked").length;
if(countchecked > 4) {
$("table input:checkbox").not(":checked").attr("disabled", true);
} else {}
});