This question already has an answer here:
I have 8 input[type="checkbox"]
. User can select only 3 checkbox at a time. If user selects the 4th checkbox then first checked (list checkbox) should unchecked. Meanwhile, if User selects 5th last selected (2nd) should deselect. I'm not able to create this logic.
var $checks = $('input:checkbox').click(function(e) {
var numChecked = $checks.filter(':checked').length;
if (numChecked > 3) {
alert("sorry, you have already selected 3 checkboxes!");
$('input:checkbox')[0].checked = false;
}
});
Aucun commentaire:
Enregistrer un commentaire