I have made a checkbox list of choices for users to select some products, but I want them to select 2 options at most. Is it possible to not let them submit the form (some kind of error message) if they select 3 or more?
Simply use the below code inside your header section:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
<script>
jQuery(function(){
var max = 2;
var checkboxes = $('input[type="checkbox"]');
checkboxes.change(function(){
var current = checkboxes.filter(':checked').length;
checkboxes.filter(':not(:checked)').prop('disabled', current >= max);
});
});
</script>
Viewing 1 replies (of 1 total)
The topic ‘Checkbox list limit’ is closed to new replies.