I am trying to populate html select with javascript array, can you guys help me make this one work below are my codes
external javascript (I have found this code somewhere in the internet)
function setRuleName()
{ var myCars=new Array("Saab","Volvo","BMW");
var sel = document.getElementById("dropping") // find the drop down
for (var i in myCars)
{ // loop through all elements
var opt = document.createElement("option"); // Create the new element
opt.value = title[i]; // set the value
opt.text = title[i]; // set the text
sel.appendChild(opt); // add it to the select
}
}
html code
<Select onclick="setRuleName();" id="dropping" >
</Select>
myCars[i]nottitle[i]onclick, or it will append theoptions every time you click.