Solved

Javascript copy dropdown value

Posted on 2011-09-21
2
242 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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

772 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

14 Experts available now in Live!

Get 1:1 Help Now