473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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, 624 views)
Feb 25 '11 #1
6 7231
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

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

Similar topics

2
by: Chad | last post by:
I am trying to burn copies of our website on CDROM's and having problems because the ASP's cannot work without the existance of a server that supports ASP's. Does anyone have a suggestion or know...
9
by: Kelly Vernon | last post by:
I have a standard ASP page that appends to an xml page. Currently if there is more than one person attempting to append to the same XML file at a time. One user will have the ability to append,...
0
by: FB Dev 1 | last post by:
When I attempt to expose a Web service method to populate a collection, .NET turns the collection into an array when I reference the Web service. This will not work for me without some big code...
7
by: Shoveler | last post by:
I'm trying to send an ARP to determine different devices on the network. I need to see the MAC address of my devices on my LAN. With the MAC I can determine if I need to talk to that devices. I...
10
by: | last post by:
If I have an array of int: int array; I suppose the correct way to clear it using memset() would be: memset(array, 0, 8 * sizeof(int)); However, I've seen the following in a piece of code:...
1
by: GeeBee | last post by:
1) I’m using Borland C++ Builder 1.0 (a very old (but still good) version). 2) I have an application EXE calling a DLL. 3) A function in the DLL receives a parameter defined as "ostream &" , and...
11
by: dalu.gelu | last post by:
Hi, can anyone help me by writing a sample code of defining a copy constructor in a class having data member as an object of another class. for eg: class A{ int x; public: A(){ x=6;} };
2
by: rahulrsh | last post by:
I am looking to write a C program... part of the work to be done involves writing data to addresses. For eg: I am required to write 0xCAFEBABE to address 0x00003000. How can I do it using C Do...
3
printedgoods
by: printedgoods | last post by:
Hello All! I have a shipping profile page that i created and works perfectly. User can create multiple shipping addresses that post to an access DB and they can then edit them (1 at a time). I...
4
nomad
by: nomad | last post by:
If I understand this right modules is used to divide a number and if there is a remainder that remainder is used? here is part of a code that I'm trying to understand which produce part of a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.