-1

I have a checkbox:

<input type="checkbox" id="catDescript" class="category_description" name="aisis_options[category_description]" value="category_description">

and a text area

<textarea id="categoryHeader" class="input-xlarge" name="aisis_options[category_header_text]" rows="10" cols="100%"></textarea>

and the following Jquery, which is suppose to one disable the text area upon clicking the check box and two keep the text area disabled as long as the check box is clicked.

$("#catDescript").change(function() {
    if($(this).is(":checked")) {                
        $("#categoryHeader").attr("disabled", "disabled");
    }
    else {
        $("#categoryHeader").removeAttr("disabled");
    }
}); 

if ($('input[value=category_description]:checkbox:checked').attr('id') === "catDescript") {
    $('#categoryHeader').attr('disabled', 'disabled');
} 

The problem is, I click the check box, the text area does not become disabled. I click submit the check box is checked but the text area is not disabled.

What am I doing wrong? please post a jsfiddle.

TheWebs
  • 12,470
  • 30
  • 107
  • 211

1 Answers1

4

For modifying properties of elements, prop method should be used instead of attr.

$(function() {
    $("#catDescript").change(function() {
        $("#categoryHeader").prop("disabled", this.checked);
    }).change(); // trigger the event on DOM Ready
})
Ram
  • 143,282
  • 16
  • 168
  • 197