Solved

Javascript copy dropdown value

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

739 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