Create option element and Append option to <select> - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

Create option element and Append option to <select>

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from  ww w . ja va 2s .co m
for(var i=1; i<=5; i++){
 var option = document.createElement("option");
 option.value = i;
 option.text = i;
 document.getElementById('nr').appendChild(option);
}
    }

      </script> 
   </head> 
   <body> 
      <select id="nr"> </select>  
   </body>
</html>

Related Tutorials