Skip to content

Instantly share code, notes, and snippets.

@jklance
Created December 6, 2012 00:58
Show Gist options
  • Select an option

  • Save jklance/4220990 to your computer and use it in GitHub Desktop.

Select an option

Save jklance/4220990 to your computer and use it in GitHub Desktop.

Revisions

  1. jklance created this gist Dec 6, 2012.
    10 changes: 10 additions & 0 deletions HTML_checkbox_limiter.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    <script type="text/javascript">
    // Limit the number of checkboxes that can be selected at one time
    var checkboxLimit = 3;
    var questionTolimit = 'q3';

    $("input[type=checkbox][name="+questionTolimit+"]").click(function() {
    var checkTest = $("input[type=checkbox][name="+questionTolimit+"]:checked").length >= checkboxLimit;
    $("input[type=checkbox][name="+questionTolimit+"]").not(":checked").attr("disabled",checkTest);
    });
    </script>