Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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")
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #populate #dropdown #variable
ADD COMMENT
Topic
Name
8+3 =