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!
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!
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.
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 :-)
Nice. Another creative solution there. Thanks for sharing it.
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/