Question : populate dropdown with a variable
Answered by : jessica-koekemoer
/* HTML:
<select id="myoptions">
</select>
*/
// Javascript:
var x = "Jenny,John,Stephanie,Marc,Ryan,Jessica";
var options = x.split(",");
var select = document.getElementById('myoptions');
for(var i=0; i<options.length; i++)
{ select.options[i] = new Option(options[i], i); //new Option("Text", "Value")
}
Source : https://stackoverflow.com/questions/14523963/populating-a-drop-down-box-with-a-variable-containing-comma-seperated-values | Last Update : Thu, 11 Jun 20