Solved

Javascript copy dropdown value

Posted on 2011-09-21
2
243 Views
Last Modified: 2012-05-12
I need to copy the value of one dropdown to another in seperate forms. I am not getting any errors but this is not working.

document.formshipping.SHIP_STATE.selectedIndex=document.formdetails.CUST_STATE.selectedIndex;
0
Comment
Question by:garyilm
  • 2
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36574531
For example :
var shipState = document.getElementsByName("SHIP_STATE")[0];
var custState = document.getElementsByName("CUST_STATE")[0];
shipState.selectedIndex = custState.selectedIndex;

Test page : http://jsfiddle.net/3BTyG/
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36574552
if you set ID attribute, if better/safest :

var shipState = document.getElementById("ShipStateId");
var custState = document.getElementById("CustStateId");
shipState.selectedIndex = custState.selectedIndex;

<select id="ShipStateId" name="SHIP_STATE"

and

<select id="CustStateId" name="CUST_STATE"

Additionaly, please double check the case of field attributes (name, id of form and dropdown)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now