Solved

Javascript copy dropdown value

Posted on 2011-09-21
2
244 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

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…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

803 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