Spree Billing/Shipping Address Checkbox
My approach for something like this would be to have the two (sub-)forms wrapped in a grouping element such as a fieldset and just loop over all fields in one and match them with the other. Quick incomplete, untested example:

&lt;form&gt;
  &lt;fieldset id="shipping-address"&gt;
    &lt;input name="shipping-firstname"&gt;
    &lt;input name="shipping-lastname"&gt;
  &lt;/fieldset&gt;
  &lt;fieldset id="billing-address"&gt;
    &lt;input name="billing-firstname"&gt;
    &lt;input name="billing-lastname"&gt;
  &lt;/fieldset&gt;
&lt;/form&gt;

&lt;script&gt;
  $("shipping-address input").each(function() {
    var shippingInput = $(this);
    var billingInputName = "billing" + shippingInput.attr("name").slice(8);
    $("#billing-address [name=" + billingInputName + "]").val(shippingInput.val());
  });
&lt;/script&gt;