"M" <m@m.com> wrote in message news:6Z********************@comcast.com...
i have a drop down menu of categories. for each category is
sub-catergories. based on the category i want the second drop-down menu
to list the subcategories to correspond with the parent category. well i
have it working fine, except the second drop-down wont display the
corresponding data unless the page is refreshed twice. how do i get it to load the
first time?
i just have a simple onChange="this.form.submit();" in the parent drop
down
thanks!
Will this help? Watch for word-wrap.
<html>
<head>
<title>category.htm</title>
<script type="text/javascript">
var cats = new Array();
cats[1] = "sub-category 1a,sub-category 1b,sub-category 1c";
cats[2] = "sub-category 2a,sub-category 2b,sub-category 2c";
function opts(that) {
document.form1.Subcategory.options.length = 0;
var catn = that.options[that.selectedIndex].value;
if (catn > 0) {
var catz = cats[catn].split(",");
for (var i=0; i<catz.length; i++) {
document.form1.Subcategory.options[i+1] = new Option(catz[i],
i+1);
}
}
}
</script>
</head>
<body>
<form name="form1">
<b>Category:</b>
<select name="Category" onchange="opts(this)">
<option value=""></option>
<option value="1">Category 1</option>
<option value="2">Category 2</option>
</select>
<b>Sub-Category:</b>
<select name="Subcategory" style="width:150px">
<option value=""></option>
</select>
</body>
</html>