Solved

Javascript copy dropdown value

Posted on 2011-09-21
2
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

628 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