Demo of Limiting maximum number of checkboxes can be selected
Check and uncheck the checkboxes to check maximum allowed selection of checkboxes.
JQuery
<script>
$(document).ready(function() {
$('input[type="checkbox"]').change(function(){
var total_checked= $("input[type='checkbox']:checked").length
if(total_checked >=3 ){
$(this).prop("checked", false );
$("#d1").html(" You have reached your maximum limit " );
} else {
$("#d1").html("Total Number of checkbox checked = " + total_checked );
}
});
////
var total_checked= $("input[type='checkbox']:checked").length;
$("#d1").html("Total Number of checkbox checked = " + total_checked );
////
});
</script>
HTML
<input type=checkbox id='ckb1' value=One> One <br>
<input type=checkbox id='ckb2' value=Two> Two <br>
<input type=checkbox id='ckb3' value=Three> Three <br>
<input type=checkbox id='ckb4' value=Four> Four <br>
<input type=checkbox id='ckb5' value=Five> Five <br>
<button type='button' class='btn btn-secondary' id=d1></button>