jQuery in Action
204
CHAPTER 7
Extending jQuery with custom plugins
    <script type="text/javascript"
            src="jquery.jqia.setreadonly.js"></script>
    <script type="text/javascript">
      $(function(){
        $('#sameAddressControl').click(function(){
          var same = this.checked;
          $('#billAddress').val(same ? $('#shipAddress').val():'');
          $('#billCity').val(same ? $('#shipCity').val():'');
          $('#billState').val(same ? $('#shipState').val():'');
          $('#billZip').val(same ? $('#shipZip').val():'');
          $('#billingAddress input')   
            .setReadOnly(same);        
        });
      });
    </script>
  </head>
  <body>
    <fieldset>
      <legend>The Test Form</legend>
      <div>
        <form name="testForm">
          <div>
            <label>First name:</label>
            <input type="text" name="firstName" id="firstName"/>
          </div>
          <div>
            <label>Last name:</label>
            <input type="text" name="lastName" id="lastName"/>
          </div>
          <div id="shippingAddress">
            <h2>Shipping address</h2>
            <div>
              <label>Street address:</label>
              <input type="text" name="shipAddress"
                     id="shipAddress"/>
            </div>
            <div>
              <label>City, state, zip:</label>
              <input type="text" name="shipCity" id="shipCity"/>
              <input type="text" name="shipState" id="shipState"/>
              <input type="text" name="shipZip" id="shipZip"/>
            </div>
          </div>
          <div id="billingAddress">
            <h2>Billing address</h2>
            <div>
              <input type="checkbox" id="sameAddressControl"/>
              Billing address is same as shipping address
            </div>
            <div>
              <label>Street address:</label>
Applies the new plugin
b