Add <Option> to <select> - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option


Add <Option> to <select>

Demo Code

ResultView the demo in separate window

      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//www.  j a va2s. co m
var values = ["First", "Second", "Third"];
var oDDL = document.getElementById("my");
for (var i = 0; i < values.length; i++) {
    var option = new Option();
    option.value = option.text = values[i];

      <select id="my"></select>  

Related Tutorials