I have 20 Checkboxes. I need to disable 16 Checkboxes, if 4 checkboxes are selected.
I tryed this begann with this jquery code
$("input[type=checkbox][name=cate]:checked").each( function() { } );
What i need is if a user selects 4 checkboxes then all other checkboxes should be disabled.
Adding a Checkbox Limit Next, within the Field Options panel, click on the Advanced tab to open the field's advanced options. Then, within the Choice Limit field, add the maximum number of checkboxes you'd like your users to be able to select. For our example, we'll limit our users to only 2 choices.
Since we need to limit the number of selections we need to call a function or submit our form every time a selection is made in the check box list. For this we will use the property AutoPostBack; set it to "true" since we need to call a function on every Post Back to trigger an event when the selection changes.
A checkbox can pass one of the two values to this variable - one value for the checked state and another one for the unchecked state.
$("input[type=checkbox][name=cate]").click(function() { var bol = $("input[type=checkbox][name=cate]:checked").length >= 4; $("input[type=checkbox][name=cate]").not(":checked").attr("disabled",bol); });
demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With