Hemant Kumar
Hemant Kumar

Reputation: 4611

How can we disable the checkbox when user check the one of checbox in the Checkboxlist?

I've a table in which first row contains a checkbox list. I've a scenario like if user click any checkbox of that list the other should be disabled mode and uncheck the checkbox enable the all checkboxes.

I've tried like to disable the checkbox ,but unable to un-checkbox the checkbox it should to enable all.

var $checkboxList = $('#tr1 input[type=checkbox]');
            $checkboxList.change(function () {
                $checkboxList.each(function () {
                    if (!this.checked) {
                        this.disabled = true;
                    }
                    else {
                        this.disabled = false;
                    }
                });
            }); 

how can we hold the state of checkboxes in case of paging ?

Upvotes: 0

Views: 145

Answers (1)

billyonecan
billyonecan

Reputation: 20270

In answer to your first question, you can just set .prop('disabled') based on the value of this.checked:

$checkboxList.change(function () {
    $checkboxList.not(this).prop('disabled', this.checked); 
}); 

Here's a fiddle

Upvotes: 3

Related Questions