I currently have two selectbox, the first for categories and the second for subcategories. When an option from the category selectbox is chosen I would like the subcategory selectbox to be filled with options drawn from an array.
The following code I have works for Chrome and Firefox but not in IE, I would appreciate any help to fix the code or new code which does a similar function.
HTML:
Code:
<select size="9" id="category" name="category" onclick="return categoryChange();">
<option>Antiques ></option>
<option>Art and Crafts ></option>
</select>
<select style="visibility:hidden" id="subcategory" name="subcategory" size="9">
</select>
JAVASCRIPT
:
Code:
function addOption(selectbox,text,value){
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
var antiques = new Array("Furniture","Ceramics","Glass");
var art = new Array("Drawings and Paintings","Photographs");
function categoryChange(){
document.getElementById("subcategory").style.visibility = "visible";
document.getElementById("subcategory").innerHTML = "";
if(document.getElementById("category").value == "Antiques >"){
for (var i=0; i < antiques.length;++i){
addOption(document.myForm.subcategory, antiques[i], antiques[i]);
}
}
else if(document.getElementById("category").value == "Art and Crafts >"){
for (var i=0; i < art.length;++i){
addOption(document.myForm.subcategory, art[i], art[i]);
}
}
}