Jump to: navigation, search

JavaScript select option

From w3cyberlearnings

How to change the first select option, and so the second option is also changed

  • When you change the first select option.
  • Thus, the second select option is also changed.
<html>
	<head>
		<title>Select Option</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script>
		function change_menu(ID_menu1, ID_menu2) {
		    var select_menu1 = document.getElementById(ID_menu1);
		    var select_menu2 = document.getElementById(ID_menu2);
		    var menu_2_value 
                      = select_menu1.options[select_menu1.selectedIndex+1].value;
		    select_menu2.value=menu_2_value;
		}  
		</script>
	</head>

	<body>
      <form id="aform">
	Start
	<select id="mmenu1" size="1" 
             onchange="change_menu(menu1='mmenu1',menu2='mmenu2');">
	    <option value="1" selected="selected">1</option>
	    <option value="2">2</option>
	    <option value="3">3</option>
	    <option value="4">4</option>
	</select>
	End
	<select id="mmenu2" size="1">
	    <option value="1">1</option>
	    <option value="2"  selected="selected">2</option>
	    <option value="3">3</option>
	    <option value="4">4</option>
	</select>
       </form>
    </body>
</html>
Navigation
Web
SQL
MISC
References