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
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.

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.