Click to See Complete Forum and Search --> : How to display/hide dropdown box due to selection


ben_johnson1991
03-03-2010, 08:31 PM
Hey,
I've got 3 drop down boxes, the first is 'type' and the 2 others are 'subtypes'.
Basically, when either of the 2 options from 'type' are selected, I want a specific 'subtype' dropdown to display.

so far i have...

<select name="type" id="type" style="width:140px;" >
<option value="opt1" onchange="document.getElementById('subV').style.display='block'; document.getElementById('subP').style.display='none';">opt1</option>
<option value="opt2"
onchange="document.getElementById('subP').style.display='block'; document.getElementById('subV').style.display='none';">opt2</option>
</select>


and the other two dropdowns with the style display:none;.

How do i get this to work as there is no displaying of the 'subtypes'.

Cheers for any help!!

Fang
03-04-2010, 05:15 AM
The onchange must be in the select, as IE does not support events in option

ben_johnson1991
03-04-2010, 05:24 AM
How would I script that?
From what you saying it would seem that it wouldn't give the option of what is visible depending on the selection?

Do I have to verify a specific script in the <select> what each option does?

Sorry, but could you give me a bit more detail?

cheers.

Fang
03-04-2010, 05:35 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
function toggle(opt) {
switch(opt) {
case 'opt1':
document.getElementById('subV').style.display='block'; document.getElementById('subP').style.display='none';
break;
case 'opt2':
document.getElementById('subP').style.display='block'; document.getElementById('subV').style.display='none';
break;
default:
alert('not a valid option');
}
}
</script>

</head>
<body>
<select name="type" id="type" style="width:140px;" onchange="toggle(this.value);">
<option value="opt1">opt1</option>
<option value="opt2">opt2</option>
</select>

</body>
</html>