Jump to content

[SOLVED] copy field input to another field


severndigital

Recommended Posts

does anyone know of a good in-depth tutorial on how to do this?? basically copying billing information fields to shipping information fields.

 

i can only find completed scripts and i was looking to learn how to and more importantly what is happening when i script this.

 

instead of just copy/pasting code.

 

thanks in advance,

chris

 

Link to comment
https://forums.phpfreaks.com/topic/53586-solved-copy-field-input-to-another-field/
Share on other sites

Here is an easy way to do it without too much work,

 

let's say you have address_line1, address_line2, city, state, zip

 

So you'll have the shipping and billing address something similar to this (I use id to make it easier)

....
<input type="text" name="address_line1_shipping" id="address_line1_shipping"
....
<input type="text" name="address_line1_billing" id="address_line1_billing"
.....

Now, you need a checkbox, button, or a link that will have an onclick event to call the function that will copy the data.

<a href="#" onclick="fill_shipping(); return false;">Copy Address</a>

 

Your javascript function will take the information from the billing and put in the shipping fields, for the state select menu, you can use the selectedIndex to change the selection

function fill_shipping(){
   document.getElementById('address_line1_shipping').value = document.getElementById('address_line1_billing').value;
   ...
   document.getElementById('state_shipping').selectedIndex = document.getElementById('state_billing').selectedIndex;
   ...
}

This is the general idea, hope this helps.

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.