Copying one form's values to another form using JQuery
<p>I have a "shipping" form that I want to offer users the ability to copy their input values over to their "billing" form by simply checking a checkbox. </p>

<p>I've coded up a solution that works -- but, I'm sort of new to jQuery and wanted some criticism on how I went about achieving this.  Is this well done -- any refactorings you'd recommend?</p>

<p>Any advice would be much appreciated!</p>

<p>The Script</p>

<pre><code>&lt;script type="text/javascript"&gt;
$(function() {
   $("#copy").click(function() {
  if($(this).is(":checked")){
    var $allShippingInputs = $(":input:not(input[type=submit])", "form#shipping");
    $allShippingInputs.each(function() {
      var billingInput = "#" + this.name.replace("ship", "bill");
      $(billingInput).val($(this).val());
    })
    //console.log("checked");
  } else {
    $(':input','#billing')
    .not(':button, :submit, :reset, :hidden')
    .val('')
    .removeAttr('checked')
    .removeAttr('selected');
    //console.log("not checked")
  }
 });
});
&lt;/script&gt;
</code></pre>

<p>The Form</p>

<pre><code>&lt;div&gt;
  &lt;form action="" method="get" name="shipping" id="shipping"&gt;
    &lt;fieldset&gt;
      &lt;legend&gt;Shipping&lt;/legend&gt;
      &lt;ul&gt;
        &lt;li&gt;
          &lt;label for="ship_first_name"&gt;First Name:&lt;/label&gt;
          &lt;input type="text" name="ship_first_name" id="ship_first_name" value="John" size="" /&gt;
        &lt;/li&gt;
        &lt;li&gt;
          &lt;label for="ship_last_name"&gt;Last Name:&lt;/label&gt;
          &lt;input type="text" name="ship_last_name" id="ship_last_name" value="Smith" size="" /&gt;
        &lt;/li&gt;
        &lt;li&gt;
          &lt;label for="ship_state"&gt;State:&lt;/label&gt;
          &lt;select name="ship_state" id="ship_state"&gt;
            &lt;option value="RI"&gt;Rhode Island&lt;/option&gt;
            &lt;option value="VT" selected="selected"&gt;Vermont&lt;/option&gt;
            &lt;option value="CT"&gt;Connecticut&lt;/option&gt;
          &lt;/select&gt;
        &lt;/li&gt;
        &lt;li&gt;
          &lt;label for="ship_zip_code"&gt;Zip Code&lt;/label&gt;
          &lt;input type="text" name="ship_zip_code" id="ship_zip_code" value="05401" size="8" /&gt;
        &lt;/li&gt;
        &lt;li&gt;
          &lt;input type="submit" name="" /&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt;
&lt;/div&gt;
&lt;div&gt;
  &lt;form action="" method="get" name="billing" id="billing"&gt;
    &lt;fieldset&gt;
      &lt;legend&gt;Billing&lt;/legend&gt;
      &lt;ul&gt;
        &lt;li&gt;
          &lt;input type="checkbox" name="copy" id="copy" /&gt;
          &lt;label for="copy"&gt;Same of my shipping&lt;/label&gt;
        &lt;/li&gt;
        &lt;li&gt;
          &lt;label for="bill_first_name"&gt;First Name:&lt;/label&gt;
          &lt;input type="text" name="bill_first_name" id="bill_first_name" value="" size="" /&gt;
        &lt;/li&gt;
        &lt;li&gt;
          &lt;label for="bill_last_name"&gt;Last Name:&lt;/label&gt;
          &lt;input type="text" name="bill_last_name" id="bill_last_name" value="" size="" /&gt;
        &lt;/li&gt;
        &lt;li&gt;
          &lt;label for="bill_state"&gt;State:&lt;/label&gt;
          &lt;select name="bill_state" id="bill_state"&gt;
            &lt;option&gt;-- Choose State --&lt;/option&gt;
            &lt;option value="RI"&gt;Rhode Island&lt;/option&gt;
            &lt;option value="VT"&gt;Vermont&lt;/option&gt;
            &lt;option value="CT"&gt;Connecticut&lt;/option&gt;
          &lt;/select&gt;
        &lt;/li&gt;
        &lt;li&gt;
          &lt;label for="bill_zip_code"&gt;Zip Code&lt;/label&gt;
          &lt;input type="text" name="bill_zip_code" id="bill_zip_code" value="" size="8" /&gt;
        &lt;/li&gt;
        &lt;li&gt;
          &lt;input type="submit" name="" /&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt;
&lt;/div&gt;
</code></pre>
