PDA

View Full Version : help with list checkboxes



lalein
05-12-2008, 11:08 AM
Hello everybody, i'm starting with javascript and i have this problem: if you select an item in a dropdownlist then you should get a list of checkboxes acording to the item selected. The problem is that i need the checkboxlist inside a particular div (div id='products'). How can i do it? This is the code i have:
<script>
function favBrowser(){
var listCheckboxes ="";
var mylist=document.getElementById("myList");
valueSelected = mylist.options[mylist.selectedIndex].value;
switch (valueSelected)
{case "Fruits":
var product = new Array();
product[0] = "apple";
product[1] = "banana";
product[2] = "ananas";
break;
case "Vegetables":
var product = new Array();
product[0] = "carrot";
product[1] = "peper";
product[2] = "tomate";
break;
case "Fish":
var product = new Array();
product[0] = "Salmon";
product[1] = "tuna";
product[2] = "octopus";
break;
}
for (x in product)
{
listCheckboxes += "<input type='checkbox' value='"+ mycars[x] +"'>" + mycars[x] + "<br />";}
document.getElementById('products').innerHTML = listCheckboxes;
}
}
</script>
<body>
<div id="content">
<form><select id="myList" onChange="favBrowser()">
<option selected>
<option value="Fruits">Fruits</option>
<option value="Groenten">Groenten</option>
<option value="Conservas">Conservas</option>
</select></form>
</div>
<div id="products"></div>
</body>