No Comments

Author: samdiaz Posted On: April 2nd, 2013 In:Tips and Tricks

Working on a new project for my job, I came across a need for limiting the number of selected checkboxes in a form. After searching online for a bit, I found this script which worked perfectly!

[cc lang=”javascript”]

// when user updates a checkbox.

// total allowed to be checked.
var max_allowed = 2;
// count how many checked.
var checked = $(“input:checked”).size();

// perform test.
if ( checked > max_allowed ) {

// is more than the max so uncheck.
$(this).attr(“checked”, false);

// display error message.
alert(“Please select a maximum of ” + max_allowed + ” options.”);




(Source: Jim Lam)

Leave a Reply

Your email address will not be published. Required fields are marked *