I have 4 checkboxes and I want to limit the selection up to 3. Did my google search, found a working one:
This is my code:
<html>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
var limit = 3;
$('input.ko_chk').on('change', function(evt) {
if($(this).siblings(':checked').length >= limit) {
this.checked = false;
}
});
</script>
<body>
<input type="checkbox" class="ko_chk" name="first" value="1"><br>
<input type="checkbox" class="ko_chk" name="second" value="2"><br>
<input type="checkbox" class="ko_chk" name="third" value="3"><br>
<input type="checkbox" class="ko_chk" name="fourth" value="4">
</body>
</html>
Still...
So, how is my code different?
Aucun commentaire:
Enregistrer un commentaire