473,405 Members | 2,261 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,405 software developers and data experts.

How do I un-select a drop-down selection when a checkbox is un-checked?

I have a checkbox that when selected it fills in the shipping address(to match the billing address. When un-checked it should clear all the fields in the shipping address section of the form. It works up until the drop downs. I have tried multiple ways of formatting it but i can't seem to get it to clear once the checkbox is un-checked. Any assistance would be great.

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. var shipName = "";
  3. var shipStreet = "";
  4. var shipStreet2 = "";
  5. var shipCity = "";
  6. var shipcountrySelect = 0;
  7. var shipProvState = 0;
  8. var shipPostalZip = "";
  9. var shipDayPhone1 = "";
  10. var shipDayPhone2 = "";
  11. var shipDayPhone3 = "";
  12. var shipCellPhone1 = "";
  13. var shipCellPhone2 = "";
  14. var shipCellPhone3 = "";
  15. var shipEmail = "";
  16.  
  17. function FillFields(box) {
  18.  if(document.bookform.box.checked) {
  19. document.bookform.shipName.value = document.bookform.billName.value;
  20. document.bookform.shipStreet.value = document.bookform.billStreet.value;
  21. document.bookform.shipStreet2.value = document.bookform.billStreet2.value;
  22. document.bookform.shipCity.value = document.bookform.billCity.value;
  23. document.bookform.shipCountrySelect.selectedIndex = document.bookform.billCountrySelect.selectedIndex;
  24. document.bookform.shipProvState.selectedIndex = document.bookform.billProvState.selectedIndex;
  25. document.bookform.shipPostalZip.value = document.bookform.billPostalZip.value;
  26. document.bookform.shipDayPhone1.value = document.bookform.billDayPhone1.value;
  27. document.bookform.shipDayPhone2.value = document.bookform.billDayPhone2.value;
  28. document.bookform.shipDayPhone3.value = document.bookform.billDayPhone3.value;
  29. document.bookform.shipCellPhone1.value = document.bookform.billCellPhone1.value;
  30. document.bookform.shipCellPhone2.value = document.bookform.billCellPhone2.value;
  31. document.bookform.shipCellPhone3.value = document.bookform.billCellPhone3.value;
  32. document.bookform.shipEmail.value = document.bookform.billEmail.value;
  33. }
  34. else {
  35. document.bookform.shipName.value = shipName;
  36. document.bookform.shipStreet.value = shipStreet;
  37. document.bookform.shipStreet2.value = shipStreet2;
  38. document.bookform.shipCity.value = shipCity;
  39. document.bookform.shipcountrySelect.value = shipcountrySelect.options[0].selected = true;
  40. document.bookform.shipProvState.value = shipProvState.options[0].selected = true;
  41. document.bookform.shipPostalZip.value = shipPostalZip;
  42. document.bookform.shipDayPhone1.value = shipDayPhone1;
  43. document.bookform.shipDayPhone2.value = shipDayPhone2;
  44. document.bookform.shipDayPhone3.value = shipDayPhone3;
  45. document.bookform.shipCellPhone1.value = shipCellPhone1;
  46. document.bookform.shipCellPhone2.value = shipCellPhone2;
  47. document.bookform.shipCellPhone3.value = shipCellPhone3;
  48. document.bookform.shipEmail.value = shipEmail;
  49.    }
  50. }
  51. </script>
  52.  
Thanks
Mar 9 '11 #1
4 1705
acoder
16,027 Expert Mod 8TB
Assuming the first option is the default empty option, set the select object selectedIndex to 0:
Expand|Select|Wrap|Line Numbers
  1. selObj.selectedIndex = 0;
Mar 9 '11 #2
I've tried that but I'm just not sure how exactly to do that within my code and have it work.
Mar 9 '11 #3
acoder
16,027 Expert Mod 8TB
Change lines 39/40 to be like 23/4, but replace the billing part with 0, e.g.
Expand|Select|Wrap|Line Numbers
  1. document.bookform.shipCountrySelect.selectedIndex = 0;
Mar 10 '11 #4
Thanks! That's was what i was looking for :)
Mar 10 '11 #5

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

Similar topics

4
by: Targa | last post by:
I have a form in which I want to have an button(image) displayed next to a checkbox when it is checked. If the box is unchecked, the button should disappear. How can I do this? Thanks!
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
1
by: Jon | last post by:
Hi, How to make a combobox that always show as dropdown even when user click on other places of the windows form? By setting combobox.dropdown = TRUE. This work if the focus is on the...
2
by: Javier | last post by:
Hi Everyone, I have a dynamic checkbox in a datagrid that uses the ITemplate interface and has the checkchanged event wired up. When the checkbox is checked, the event event handler that...
1
by: priyanka.freakout | last post by:
Hi All, In my form I have created a dropdown box which is populated with data from a database on page load and i have also created a dropdwon box and what i intend on doing is displaying data...
0
by: Jayender | last post by:
Hi , I have placed checkbox in my gridview .. now when i check the chekbox and click anybutton the checkbox becomes unchecked. but when i normally add checkbox in the page it doesnt happen but...
3
by: kandisbarr | last post by:
Please help! I'm new to TheScripts ... I've been stuck on this problem for days and I've lost my mind because of it! I have created a Data Access Page, using Access 2003, named...
2
by: rote | last post by:
If you have a look at this site below you will notice that after typing some text and the list is too long the textbox will give you like a dropdown list...
2
by: polluxsoftech | last post by:
i want to enter text in textbox by dropdown only when clicking on button i want that all this perform at client side by javascript.. this is dont in apsx page but i want it in .ascx this is...
2
by: azegurb | last post by:
hi i have created function that automatically adds rows with chekcboxes. i can create two button that one serves checking all checkboxes and the another one serves for unchecking rows. but i would...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.