Created
June 21, 2012 14:59
-
-
Save garethredfern/2966230 to your computer and use it in GitHub Desktop.
Copy Billing Info To Shipping Info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Needs the select plugin to enable select boxes to change: https://github.com/SamWM/jQuery-Plugins