I'm having an issue with Javascript. I'm trying to limit the number of checked checkbox to 5. I have a Javascript script that shows me the alert I ask to show but the still put the checkbox on checked.
To do so I'm using this Javascript script:
function change(_this) {
if ($('input[type=checkbox]:checked').length > 5) {
alert("allowed only 5");
this.checked = false;
}
}
I've tried also
$(this).prop('checked', false);
And my checkboxes are the classical one
<input type="checkbox" name="memberName" value="Name1" onchange="change(this)">
<input type="checkbox" name="memberName" value="Name2" onchange="change(this)">
<input type="checkbox" name="memberName" value="Name3" onchange="change(this)">
<input type="checkbox" name="memberName" value="Name4" onchange="change(this)">
<input type="checkbox" name="memberName" value="Name5" onchange="change(this)">
<input type="checkbox" name="memberName" value="Name6" onchange="change(this)">
What can cause this issue?
Aucun commentaire:
Enregistrer un commentaire