Chage Value On Select

Here is a JavaScript code for you to use in your web pages. Options in second drop down menu change with a change in the value of first drop down menu. Copy the code and paste it in Notepad, save it as test.html and "test" it.


<html>
<head>
<Script Language="JavaScript">
function setOptions(chosen) {
var selbox = document.myform.opttwo;
selbox.options.length = 0;
if (chosen == " ") {
selbox.options[selbox.options.length]
= new Option('Select From Above',' ');
}
if (chosen == "1") {
selbox.options[selbox.options.length]
= new Option('USA',
'You have chosen USA from Countries');
selbox.options[selbox.options.length]
= new Option('UK',
'You have chosen UK from Countries');
}
if (chosen == "2") {
selbox.options[selbox.options.length]
= new Option('Freeware',
'You have chosen Freeware from Softwares');
selbox.options[selbox.options.length]
= new Option('Shareware',
'You have chosen Shareware from Softwares');
}
if (chosen == "3") {
selbox.options[selbox.options.length]
= new Option('English',
'You have chosen English from Languages');
selbox.options[selbox.options.length]
= new Option('French',
'You have chosen French from Languages');
}
}
</script>
</head>
<body>
<form name="myform"><div align="center">
<select name="optone" size="1"
onchange="setOptions(document.myform.optone.options
[document.myform.optone.selectedIndex].value);">
<option value=" " selected="selected"> </option>
<option value="1">Countries</option>
<option value="2">Softwares</option>
<option value="3">Languages</option>
</select><br /> <br />
<select name="opttwo" size="1">
<option value=" " selected="selected">
Select From Above</option>
</select>
<input type="submit" name="go" value="Go"
onclick="alert(document.myform.opttwo.options
[document.myform.opttwo.selectedIndex].value);">
</div></form>
</body>
</html>