[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…
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…

649 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