Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit Checkbox amount

Tags:

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.

like image 652
streetparade Avatar asked Jun 03 '10 13:06

streetparade


People also ask

How do I limit the number of selected checkboxes?

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.

How can I limit the number of checkbox selections using C #)?

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.

How many values of checkbox can have?

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.


1 Answers

$("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

like image 96
Reigel Avatar answered Sep 28 '22 14:09

Reigel