S
shankwheat
I'm passing a string like 'Div3,Div4' to use as options in a selectbox
but I need the text the user sees in the box different from the values.
My code populates the values in the selectbox correctly but not the
text. Thanks
Desired end result:
<select id="selectBox" multiple="multiple" size="4">
<option value="Div3">About the Company</option>
<option value="Div1">Ratings</option>
</select>
I tried this but it's not working. No errors
optionsString = "Div3,Div1";
optionsArray = optionsString.split(",");
var sb = document.getElementById("selectBox");
for (i=0; i < optionsArray.length; i++) {
var opt = document.createElement("OPTION");
opt.setAttribute("value",optionsArray);
var commonName = optionsArray;
if (commonName == "Div1") {
opt.setAttribute("text","Ratings");
} else if (commonName == "Div3") {
opt.setAttribute("text","About the Company");
}
opt.appendChild(document.createTextNode(optionsArray ));
sb.appendChild(opt);
}
}
but I need the text the user sees in the box different from the values.
My code populates the values in the selectbox correctly but not the
text. Thanks
Desired end result:
<select id="selectBox" multiple="multiple" size="4">
<option value="Div3">About the Company</option>
<option value="Div1">Ratings</option>
</select>
I tried this but it's not working. No errors
optionsString = "Div3,Div1";
optionsArray = optionsString.split(",");
var sb = document.getElementById("selectBox");
for (i=0; i < optionsArray.length; i++) {
var opt = document.createElement("OPTION");
opt.setAttribute("value",optionsArray);
var commonName = optionsArray;
if (commonName == "Div1") {
opt.setAttribute("text","Ratings");
} else if (commonName == "Div3") {
opt.setAttribute("text","About the Company");
}
opt.appendChild(document.createTextNode(optionsArray ));
sb.appendChild(opt);
}
}