Limit checked checkbox in a form
html, javascript, jquery
Solution
This example will count the number of checked inputs after each one is checked and compare against the maximum number allowed. If the maximum is exceeded, the remaining checkboxes are disabled.
jQuery(function(){
var max = 3;
var checkboxes = $('input[type="checkbox"]');
checkboxes.change(function(){
var current = checkboxes.filter(':checked').length;
checkboxes.filter(':not(:checked)').prop('disabled', current >= max);
});
});
Here is a working example - http://jsfiddle.net/jaredhoyt/Ghtbu/1/
Problem
I have an HTML form with a set of checkboxes, how to make the user can only check a fixed number of them