PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Limiting the amount of checkboxes that can be checked

  1. Is there a simple way to limit the amount of checkboxes that can be checked? For example, I have a form with 8 checkboxes, from which a user can choose to check a maximum of three.

    Thanks in advance!

    Posted 13 years ago on Monday July 5, 2010 | Permalink
  2. There's not a built-in way to do this at the moment, but you can do this with a couple of lines of jQuery.

    <script type="text/javascript">
    jQuery.noConflict();
      jQuery(document).ready(function($) {		
    
     	$.fn.limit = function(n) {
     	var self = this;
     	this.click(function(){ return (self.filter(":checked").length<=n); });
    	}
    	$("ul#input_1_15 li input:checkbox").limit(3);  				
    
      });
    </script>

    It worked well in my tests.. just swap the "input_1_15" for the actual list ID from your form and you should be good to go.

    Posted 13 years ago on Monday July 5, 2010 | Permalink
  3. Thanks Kevin! Very handy little script!

    I figured out a simple work around too: instead of a big list of checkboxes (12, in this case), offer three drop-down menus, each with all possible choices :-)

    Posted 13 years ago on Monday July 5, 2010 | Permalink
  4. Nice. Another creative solution there. Thanks for sharing it.

    Posted 13 years ago on Monday July 5, 2010 | Permalink
  5. A new method based on this older method which disables unchecked checkboxes once the limit has been reached. This resolves this issue some users were experiencing with this older method and conditional logic.

    http://gravitywiz.com/2012/06/11/limiting-how-many-checkboxes-can-be-checked/

    Posted 11 years ago on Monday June 11, 2012 | Permalink

This topic has been resolved and has been closed to new replies.