1

I have the below syntax which unchecks a checkbox.

$('#h12_1').attr('checked','checked');

h12_1 is the name of my checkbox.

How do I disable the checkbox so it cannot be checked? similarly how do I enable the checkbox again?

Something like this:

 $.post('get_as_12', {data:selectedObj.value},function(result) {
 alert(result[0]) ;

      if(result[0] > 0) {
          $('#h12_1').attr('checked','enabled');
          $('#h12_1').attr('checked','checked');
       } else {
          $('#h15_1').attr('disabled');
          $('#h15_1').removeAttr('checked');
      }
 }); 

2 Answers 2

5

For disabling you should use disabled attribute or property (the latter is preferrable):

$("#h12_1").attr("disabled", "disabled");  // removeAttr("disabled") to enable
// or
$("#h12_1").prop("disabled", true);        // false to enable
Sign up to request clarification or add additional context in comments.

1 Comment

Just 2 secs late!! so u get +1
1

To disable checkbox, use disabled attribute.

$("#h12_1").attr("disabled", "disabled");

To enable it back again use removeAttr().

$('#h15_1').removeAttr('disabled');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.