Advertisement
Guest User

JQuery Copy Billing Address to Shipping, Save Defaults

a guest
Feb 27th, 2010
2,641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // copy billing to shipping
  2.     $('input#billCopy').click(function() {
  3.  
  4.         // If checked
  5.         if ($(this).is(":checked")) {
  6.  
  7.             //for each input field
  8.             $('#shipFields input', ':visible', document.body).each(function(i) {
  9.  
  10.                 //copy the values from the billing inputs
  11.                 //to the equiv inputs on the shipping inputs
  12.                 $(this).val($("#billFields input").eq(i).val());
  13.             });
  14.  
  15.             //won't work on drop downs, so get those values
  16.             var billState = $("select#billState").val();
  17.  
  18.             // special for the select
  19.             $('select#shipState option[value=' + billState + ']').attr('selected', 'selected');
  20.  
  21.         }
  22.         else {
  23.  
  24.             //for each input field
  25.             $('fieldset#shipFields input', ':visible', document.body).each(function(i) {
  26.  
  27.                 // put default values back
  28.                 $(this).val($(this)[0].defaultValue);
  29.             });
  30.  
  31.             // special for the select
  32.             $('select#shipState option[value=""]').attr('selected', 'selected');
  33.  
  34.         } // end if else
  35.  
  36.     }); // end copy bill to ship function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement