469,306 Members | 2,064 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

How to copy billing address to shipping address?

Hi I am new with javascript and am trying to make it so that once the billing address on my page has been filled out, you click a checkbox(if billing info is same as shipping) and it copies the info to shipping address. I have tried approaching this several ways and tried google-ing for help as well but i cannot seem to get anything to work. Here is the code that i have most recently tried:
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.  
  3. function copyAddress
  4. {
  5. document.getElementById("billName").value = document.getElementById("shipName").value;
  6. document.getElementById("billStreet").value = document.getElementById("shipStreet").value;
  7. document.getElementById("billStreet2").value = document.getElementById("shipStreet2").value;
  8. document.getElementById("billCity").value = document.getElementById("shipCity").value;
  9. document.getElementById("billCountry").selectedIndex = document.getElementById("shipCountry").selectedIndex;
  10. document.getElementById("billProvinceState").selectedIndex = document.getElementById("shipProvinceState").selectedIndex;
  11. document.getElementById("billPostalZip").value = document.getElementById("shipPostalZip").value;
  12. document.getElementById("billDayPhone1").value = document.getElementById("shipDayPhone1").value;
  13. document.getElementById("billDayPhone2").value = document.getElementById("shipDayPhone2").value;
  14. document.getElementById("billDayPhone3").value = document.getElementById("shipDayPhone3").value;
  15. document.getElementById("billCellPhone1").value = document.getElementById("shipCellPhone1").value;
  16. document.getElementById("billCellPhone2").value = document.getElementById("shipCellPhone2").value;
  17. document.getElementById("billCellPhone3").value = document.getElementById("shipCellPhone3").value;
  18. document.getElementById("billEmail").value = document.getElementById("shipEmail").value;
  19. }
  20.  
  21. </script>
  22.  
I call it in a checkbox. I have attached the form section of the html as a text document. Another option i approached was:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2.  
  3. function FillFields(box) {
  4. if(box.checked == false) { return; }
  5.  
  6. document.bookform.billName.value = document.bookform.shipName.value;
  7. document.bookform.billStreet.value = document.bookform.shipStreet.value;
  8. document.bookform.billStreet2.value = document.bookform.shipStreet2.value;
  9. document.bookform.billCity.value = document.bookform.shipCity.value;
  10. document.bookform.billCountry.selectedIndex = document.bookform.shipCountry.selectedIndex;
  11. document.bookform.billProvinceState.selectedIndex = document.bookform.shipProvinceState.selectedIndex;
  12. document.bookform.billPostalZip.value = document.bookform.shipPostalZip.value;
  13. document.bookform.billDayPhone1.value = document.bookform.shipDayPhone1.value;
  14. document.bookform.billDayPhone2.value = document.bookform.shipDayPhone2.value;
  15. document.bookform.billDayPhone3.value = document.bookform.shipDayPhone3.value;
  16. document.bookform.billCellPhone1.value = document.bookform.shipCellPhone1.value;
  17. document.bookform.billCellPhone2.value = document.bookform.shipCellPhone2.value;
  18. document.bookform.billCellPhone3.value = document.bookform.shipCellPhone3.value;
  19. document.bookform.billEmail.value = document.bookform.shipEmail.value;
  20. }
  21.  
  22. </script>
I correctly called it in the form checkbox but it did not work either.

What am I doing wrong?
Attached Files
File Type: txt form.txt (10.5 KB, 573 views)
Feb 25 '11 #1
6 6626
johny10151981
1,059 1GB
are you getting any javascript error?

you can check javascript error using firefox and chrome.

Chrome has builtin element inspector. in case of Firefox you can install firebug adds on

Both are excellent tools for inspecting HTML and javascript...
Feb 26 '11 #2
There appears to be no errors when inspected with firebug so it has me baffled....

I took the script exerpt above from my js file that is attatched in the head section of the document. Maybe my issue is how i have called the script. Would I add the script tags to the head section or should it be added in the body below the checkbox? Here is my script tag:

<script type="text/javascript" src="javascript/form.js"></script>
Feb 26 '11 #3
Or might it possibly be that the <fieldset> is messing up the way I access the form elements?
Feb 26 '11 #4
acoder
16,027 Expert Mod 8TB
copyAddress has the parentheses missing:
Expand|Select|Wrap|Line Numbers
  1. function copyAddress() {
Feb 28 '11 #5
Yes thank you the parentheses were missing but it turns out billing info should have been where shipping info was and vice versa. Thanks
Mar 3 '11 #6
acoder
16,027 Expert Mod 8TB
A classical mistake! It's even obvious from the title. The assumptions we make...
Mar 4 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by | last post: by
nomad
4 posts views Thread by nomad | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.