javascript, select one dropdown changes the selected value of another drop downlist

Posted on 2011-03-08
Medium Priority
Last Modified: 2012-05-11
I have two drop down lists.  Selecting one dropdown changes the selected value of another drop downlist.  If "default" is chosen on list1, then select "All" on list 2.  Also disable selection on list2.  If possible, use onclick.

<select name=list1>
  <option value="default">default</option>
  <option value="choice">choice</option>

<select name=list2>
  <option value="All">All</option>
  <option value="choice1">choice1</option>
  <option value="choice1">choice2</option>
Question by:rgbcof
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
LVL 82

Accepted Solution

leakim971 earned 1000 total points
ID: 35075868
Check this :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">

	window.onload = function() {
		//var list1 = document.getElementById("list1");
		var list1 = document.getElementsByName("list1")[0];

	function updateList2(val) {
		//list2 = document.getElementById("list2");
		var list2 = document.getElementsByName("list2")[0];
		if(val == "default") {
			list2.selectedIndex = 0
			for(var i=1;i<list2.options.length;i++) {
				list2.options[i].disabled = true;
		else {
			for(var i=1;i<list2.options.length;i++) {
				list2.options[i].disabled = false;
<select name="list1" onchange="updateList2(this.value);" >
  <option value="default">default</option> 
  <option value="choice">choice</option>
<select name="list2">
  <option value="All">All</option> 
  <option value="choice1">choice1</option>
  <option value="choice1">choice2</option>

Open in new window


Author Closing Comment

ID: 35080227
leakim971 you are awesome in providing so much detail and actual code.  Thank you.
LVL 82

Expert Comment

ID: 35082096
You're welcome! Thanks for the points! Have a nice day!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
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

801 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