I have a javascript array and I want to iterate through it to create the options in a <select>
tag.
var sBoxContent = "categorieBox_content";
var oBoxContent = document.getElementById(sBoxContent);
oBoxContent.innerHTML += "<select name=\"clientCategories\">";
for(var i=0;i<oClientCategories.length;i++) {
var categorieId = oClientCategories[i].id;
var categorieLabel = oClientCategories[i].label;
oBoxContent.innerHTML += "<option value=\"" + categorieId + "\">" + categorieLabel + "</option>";
}
oBoxContent.innerHTML += "</select>";
The array is working properly since the option is displayed correctly but it appears outside the <select>
tag.
HTML:
<td>
<select name="clientCategories"></select>
<option value="1">CategoryName</option>
</td>