Something like this would work out:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Select Divs - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.prods div {
display:none;
}
</style>
<script type="text/javascript">
<!--
function UpdateList(x) {
for (var i = 3; i > 0; --i)
document.getElementById("Products_"+i).style.display = "none";
if (x.selectedIndex == 1) {
document.getElementById("Products_1").style.display = "block";
}
if (x.selectedIndex == 2) {
document.getElementById("Products_1").style.display = "block";
document.getElementById("Products_2").style.display = "block";
}
if (x.selectedIndex == 3) {
document.getElementById("Products_1").style.display = "block";
document.getElementById("Products_2").style.display = "block";
document.getElementById("Products_3").style.display = "block";
}
}
window.onload=function(){UpdateList(document.getElementById('items1'));};
// -->
</script>
</head>
<body>
<div>
The select box:<br>
<select name="items1" class="select" id="items1" onchange="UpdateList(this);">
<option>Select </option>
<option>1</option>
<option>2</option>
<option>3</option>
</select><br>
</div>
<div>
divisions:<br>
</div>
<div class="prods">
<div id="Products_1">text 1 here.
</div>
<div id="Products_2">text 2 here.
</div>
<div id="Products_3">text 3 here.
</div>
</div>
</body>
</html>
But, at that rate, the function could be simplified:
Code:
function UpdateList(x) {
for (var i = 3; i > 0; --i)
document.getElementById("Products_"+i).style.display = "none";
for (var i = x.selectedIndex; i > 0; --i)
document.getElementById("Products_"+i).style.display = "block";
}
or even:
Code:
function UpdateList(x) {
for (var i = x.options.length-1; i > 0; --i)
document.getElementById("Products_"+i).style.display = "none";
for (var i = x.selectedIndex; i > 0; --i)
document.getElementById("Products_"+i).style.display = "block";
}
In the last version, the script would calculate everything on the basis of the number options that were in the select.
Bookmarks