JQuery Copy Billing Address to Shipping, Save Defaults
By: a guest | Feb 27th, 2010 | Syntax:
JavaScript | Size: 1.17 KB | Hits: 1,740 | Expires: Never
// copy billing to shipping
$('input#billCopy').click(function() {
// If checked
if ($(this).is(":checked")) {
//for each input field
$('#shipFields input', ':visible', document.body).each(function(i) {
//copy the values from the billing inputs
//to the equiv inputs on the shipping inputs
$(this).val($("#billFields input").eq(i).val());
});
//won't work on drop downs, so get those values
var billState = $("select#billState").val();
// special for the select
$('select#shipState option[value=' + billState + ']').attr('selected', 'selected');
}
else {
//for each input field
$('fieldset#shipFields input', ':visible', document.body).each(function(i) {
// put default values back
$(this).val($(this)[0].defaultValue);
});
// special for the select
$('select#shipState option[value=""]').attr('selected', 'selected');
} // end if else
}); // end copy bill to ship function