I need your help.
I have the following function below, that reads data from an array and then dynamically adds option values to a selectbox.
Is there a way to modify the array such that I can specify the text and the option value to be added?
ABC,"testing"
DEF,"the system"
GHI,"further testing"
JKL,"desired results"
So the select box now resembles the following:
<select>
<option value="testing">ABC</option>
<option value="the system">DEF</option>
<option value="further testing">GHI</option>
<option value="desired results">JKL</option>
</select>
ie.
var y = [
"ABC",
"DEF",
"GHI",
"JKL"
]
for (var i = 0; i < y.length; i++ ){
document.getElementById('select1').options[i]=new Option(y[i], y[i])
}