By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,770 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

How to copy billing address to shipping address?

P: 11
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, 546 views)
Feb 25 '11 #1
Share this Question
Share on Google+
6 Replies


100+
P: 1,059
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

P: 11
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

P: 11
Or might it possibly be that the <fieldset> is messing up the way I access the form elements?
Feb 26 '11 #4

acoder
Expert Mod 15k+
P: 16,027
copyAddress has the parentheses missing:
Expand|Select|Wrap|Line Numbers
  1. function copyAddress() {
Feb 28 '11 #5

P: 11
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
Expert Mod 15k+
P: 16,027
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.