Limit checkbox selections

To limit the number of selections of a Checkbox add an HTML element to the form (from the “More” tab where you add elements) and enter this code as the content:

1
2
34
5
6
7
8
9
10
11
12
1314
15
16
17
18
19
20
<script>
    jQuery(document).ready(function ($) {
        var $checkboxes = $('.iphorm_1_1'); 
        $checkboxes.click(function () {
            var checked = 0;
            $checkboxes.each(function () {
                if ($(this).is(':checked')) {
                    checked++;
                }
            });
           
            if (checked > 2) {                $(this).prop('checked', false);
                $.uniform.update();
                return false;
            }
        });
    });
</script>
<script>
    jQuery(document).ready(function ($) {
        var $checkboxes = $('.iphorm_1_1');

        $checkboxes.click(function () {
            var checked = 0;
            $checkboxes.each(function () {
                if ($(this).is(':checked')) {
                    checked++;
                }
            });
           
            if (checked > 2) {
                $(this).prop('checked', false);
                $.uniform.update();
                return false;
            }
        });
    });
</script>
  • On line 3, replace iphorm_1_1 with the unique ID of the Checkbox
  • On line 13, replace the number 2 with the maximum number of selections allowed

Still having trouble? Head over to the forums.

Forums