Removing and adding disabled attribute using jQuery from html checkbox

I participate in the jQuery learning process and a bit of a pickle with adding and removing a disabled attribute from the html checkbox. I want that when you check the box, you cannot write the address in the text box, otherwise you need to select from the search box. I did this later, but the checkbox is causing my problem. This is my function call. It introduces the function just fine, but does not remove the disabled attributes during validation and throws an error that the addAttr method cannot use to add the disabled one.

//attach an event for clicking on the informal contact button
jQuery(document).ready(
    function () {
        jQuery('.InformalContact').live('click',
        function (event) {
            TestIfInformalContactIsChecked(event);
        });
    }
);

//check the status of the informalcontact checkbox when a user activates it
//If checked, user can input data in the contactinfo manually.
function TestIfInformalContactIsChecked(event) {
    var thisCheck = jQuery(event.target);
    if (thisCheck.is(':checked')) {
        jQuery("#ContactInfo").removeAttr('disabled');
    }
    else {
        jQuery("#ContactInfo").addAttr('disabled');     
    }
}

And this is html ...

<div class="TBItemColumn1">
    Name: <input id="Name" value="" class="TBFindContact" style="width: 150px;" maxlength="50" type="text" /><br />
    <input id="InformalContact" class="InformalContact" maxlength="50" type="checkbox" ClientIDMode="Static"  />Informal Contact<br />
    <div id="TBContactSearchBox"></div>
    Notes:
    <br />
    <textarea id="Notes" style="width: 280px; height: 20px;"></textarea>
  </div>
  <div class="TBItemColumn2">
    <div class="FloatLeft">
      Contact Info:
      <br />
      <textarea id="ContactInfo" value="" style="width: 280px; height: 70px;" disabled="disabled"></textarea>
    </div>
  </div>

What did I mess up with setting the disabled attribute on the checkbox?

+5
source share
1 answer

To enable use of this

jQuery("#ContactInfo").prop('disabled', true);

and disable it

jQuery("#ContactInfo").prop('disabled', false);

disabled removeAttr ( removeProp), . .

+8

All Articles