Populate Drop Down List Box with values from array (JavaScript/HTML)
I have a requirement to populate a drop down list box in my form with
human races. I believe I've done it correctly but I get an error that says
Error: Unable to get property 'appendChild' of undefined or null reference
What am I doing wrong?
HTML:
<td class="style1">
<select id="RaceDropDown" name="D1">
<option></option>
</select></td>
JavaScritpt:
var select = document.getElementById('RaceDropDown');
var options = ["Asian", "Black"];
var i;
for (i = 0; i <= options.length; i++) {
var opt = options[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
No comments:
Post a Comment