Answers for "populate dropdown with a variable"

1

populate dropdown with a variable

/* 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")
}
Posted by: Guest on June-04-2020

Code answers related to "populate dropdown with a variable"

Code answers related to "Javascript"

Browse Popular Code Answers by Language