Limits the number of checkboxes that can be checked

The good thing about jQuery is that we can extend the library very easily, and today we are going to extend it to add a function that will allow us to limit the maximum number of checked checkboxes, something that can be really interesting.

First step: Add the limitCheckbox function to jQuery:

$ .fn.limitarCheckbox = function (num) {

var check = this; (function () {return (check.filter (": checked"). length <= num);}); / * We take the number of checked checks and see if they exceed our parameter * /
Second step: We execute the function in the document.ready ()
$ ("Input: checkbox"). LimitCheckbox (6);
/ * We can use any selector as long as it has checkboxes ... and you can limit it to whatever you want * /
I hope it helps you for a project, I had to do it out of necessity right now and I couldn't help but post it for you, creatives of the world!

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Luardo Luis Eduardo said

    can you specify a little more like? any more complete code examples?

  2.   Santiago said

    GREAT !, Thanks for the contribution, I'm starting with php, jQuery and javaScrit and you helped me understand how to apply it to other functions, thanks !!