The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Limit the number of checkboxes that can be selected

Labels

This Discussion is public

Notifications

I have a checkbox with 8 options but I need to restrict the number that can be selected to 4.

Any ideas as to how I do this please?

Many thanks

Barbara

You will have to use javascript. I used the codes below in a previous site. 

// Change 2 to your limit
// Chagne 927 to the ID of the checkbox

jQuery(document).ready(function($) {
var limit = 2;
$('input[name="item_meta[927][]"]'fills).change(function() { var checkbox_num =
$("input[name='item_meta[927][]']:checked").length; if ( checkbox_num > limit )  { this.checked = false; } }); });

Thank you for trying to help Albert. Where would I paste the code? I've tried lots of places but cannot get it to work.

Discussion closed.