Skip to content Skip to sidebar Skip to footer

Limit Number Of Checkboxes To Be Selected, Jquery

A simpler version of this question has already been posted, but I'm having some difficulty. Say I have 5 checkboxes: None Apple Banana Orange Pear The user is allowed to select t

Solution 1:

Try to play with this example:

var checked = [],
$check = $('.check').change(function() {
    if (this.value == -1 && this.checked) {
        $check.not(this).prop('disabled', true).prop('checked', false);
        checked = [];
    }
    else {
        $check.prop('disabled', false);
        checked.push(this);
        checked = $(checked)
        checked.prop('checked', false).slice(-2).prop('checked', true);
    }
});

http://jsfiddle.net/q7Dve/

Post a Comment for "Limit Number Of Checkboxes To Be Selected, Jquery"