Skip to content

Instantly share code, notes, and snippets.

@garethredfern
Created June 21, 2012 14:59
Show Gist options
  • Save garethredfern/2966230 to your computer and use it in GitHub Desktop.
Save garethredfern/2966230 to your computer and use it in GitHub Desktop.
Copy Billing Info To Shipping Info
<script>
//on page load
$(document).ready( function () {
//when the checkbox is checked or unchecked
$('#copyaddress').click(function() {
// If checked
if($('#copyaddress').is(':checked')) {
//for each input field
$('#shipping input', ':visible', document.body).each(function(i) {
//copy the values from the billing_fields inputs
//to the equiv inputs on the shipping_fields
$(this).val( $('#billing input').eq(i).val() );
});
//won't work on drop downs, so get those values
var bcountry = $("#country_code").val();
// special for the select
$('select#shipping_country_code option[value=' + bcountry + ']').attr('selected', 'selected');
}
else {
//for each input field
$('#shipping input', ':visible', document.body).each(function(i) {
// put default values back
$(this).val($(this)[0].defaultValue);
});
// special for the select
$('select#shipping_country_code option[value=""]').attr('selected', 'selected');
} // end if else
});
});
</script>
@garethredfern
Copy link
Author

Needs the select plugin to enable select boxes to change: https://github.com/SamWM/jQuery-Plugins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment