why this code not working?!

why this code not working?!

Hi,

I am using the following to set the text and readonly attribute of textbox when checkbox is clicked but it's not working properly. First when I load the page it works fine.. then I set click the checkbox so it will be readonly and text will change.. then when changing it back to editable it also works but the problem occurs when I change the company name then again click the checkbox to set it to readonly... nothing will work that time.. 

  1. $("#chkHideCompanyName").click(function () {
  2.     if ($(this).is(":checked")) {
  3.         $("#txtCompany").attr("value", "Confidential");
  4.         $("#txtCompany").attr("readonly", true);
  5.     } else {
  6.         $("#txtCompany").attr("readonly", false);
  7.         $("#txtCompany").attr("value", "<?php echo $company_name; ?>");
  8.     }
  9. });