Setting the selected item of a <Select> element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select

Description

Setting the selected item of a <Select> element

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 www .j a  va 2  s . c  o  m*/
document.getElementById("a").selectedIndex =1
    });

      </script> 
   </head> 
   <body> 
      <select id="a"> 
         <option value="1">1</option> 
         <option value="2">2</option> 
      </select>  
   </body>
</html>

Related Tutorials