Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  1] [ 1]  / answers: 1 / hits: 57881  / 12 Years ago, wed, october 10, 2012, 12:00:00

The purpose is to;

If checkbox is disabled, do nothing.

If checkbox is enabled and checked, set the style of a button.

Here is what I've got so far;



 $(document).ready(function (e) {


$(.checkbox).live(click, function () {

if ($(this).hasAttribute('disabled')) {
return false;
}
var isAnyChecked;

$(input[type=checkbox]).each(function () {
var checkedValue = $(this).attr(checked);
if (checkedValue == checked) {
isAnyChecked = true;
}


});

if (isAnyChecked) {
$(#<%= btnConfirm.ClientID %>).css(display, block);

} else {
$(#<%= btnConfirm.ClientID %>).css(display, none);

}


}); });


I've tried .is(':disabled'), .hasAttr(), .prop() and .attr(). Any help would be greatly appreciated.


More From » checkbox

 Answers
23

You have to check whether the disabled attribute is true: .attr('disabled').



Or, better, use .is(':disabled').---






EDIT: So it seems that .attr is now deprecated for this use (see http://api.jquery.com/attr/)
The preferred way is:



$('#myCheckbox').prop('disabled')


It has to be noted that this still work as of today:



$('#myCheckbox').is(':disabled')


Try it here: https://jsfiddle.net/Robloche/phaqfrmj/


[#82631] Tuesday, October 9, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alfredoc

Total Points: 261
Total Questions: 128
Total Answers: 89

Location: French Polynesia
Member since Sun, Aug 2, 2020
4 Years ago
;