Skip to content

Instantly share code, notes, and snippets.

@jklance
Created December 6, 2012 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jklance/4220990 to your computer and use it in GitHub Desktop.
Save jklance/4220990 to your computer and use it in GitHub Desktop.
Limit HTML checkbox selections
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment