View Single Post
Old 03-21-2011, 12:29 PM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
As always, there are many ways to kill a cat!

Code:
<html>
<head>

<script type = "text/javascript">

function setOptions(chosen) {
var selbox = document.myform.opttwo;
 
selbox.options.length = 0;
if (chosen == "0") {
selbox.options[selbox.options.length] = new Option('Please select one of the options above first',' ');
}

if (chosen == "1") {
selbox.options[selbox.options.length] = new Option('Furniture','Furniture');
selbox.options[selbox.options.length] = new Option('Ceramics','Ceramics');
selbox.options[selbox.options.length] = new Option('Glass','Glass');
}

if (chosen == "2") {
selbox.options[selbox.options.length] = new Option('Drawings and Paintings','Drawings and Paintings');
selbox.options[selbox.options.length] = new Option('Photographs','Photographs');
}

}

</script>

</head>
<body>

<form name="myform">

<select name="optone" 
onchange="setOptions(document.myform.optone.options[document.myform.optone.selectedIndex].value);">
<option value="0" selected="selected"> Please select </option>
<option value="1"> Antiques </option>
<option value="2"> Arts and Crafts </option>
</select>
<br> <br>
<select name="opttwo">
<option value=" " selected="selected">Select a main category first</option>
</select>
<br><br>
<input type="button" name="go" value="Click To Alert Value Selected" onclick="alert(document.myform.opttwo.options[document.myform.opttwo.selectedIndex].value);">

</form> 

</body>
</html>
Philip M is offline   Reply With Quote