Can anyone think of anything more elegant?
Yes. You can use the innerHTML attribute of the select tag to create the option tags inside the select tag. Or you can use the DOM JavaScript API to create option elements and attach them as children of the select tag.
This code is untested, so it may have some bugs, but it should be close to what you need.
[HTML]
<select id="dynamicDropDown" name="dynamicDropDown" onmouseover="populate(this)" >
</select>
<script>
var options = new Array();
options[0] = "one";
options[1] = "two";
options[2] = "three";
options[3] = "four";
function populate(selectTag) {
var optHTML = "";
for( int i = 0; i < options.length; i++ ) {
optHTML += " <option value=\""+options[i]+"\" >"+options[i]+"</option>";
}
selectTag.innerHTML = optHTML;
}
</script>
[/HTML]
or
[HTML]
<select id="dynamicDropDown" name="dynamicDropDown" onmouseover="populate(this)" >
</select>
<script>
var options = new Array();
options[0] = "one";
options[1] = "two";
options[2] = "three";
options[3] = "four";
function populate(selectTag) {
for( int i = 0; i < options.length; i++ ) {
var optTag = document.createElement("option");
optTag.setAttribute("value", options[i]);
optTag.setAttribute("name", options[i]);
selectTag.appendChild(opt);
}
}
</script>
[/HTML]