Get selected value from <select> via selectedIndex - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select

Description

Get selected value from <select> via selectedIndex

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() {/*  w w w .  ja  v a2  s.co m*/
var oS = document.getElementById("my_select");
console.log(oS.options[oS.selectedIndex].value);
    });

      </script> 
   </head> 
   <body> 
      <select id="my_select"> 
         <option value="1">Foo</option> 
         <option value="2">Bar</option> 
         <option selected>Bork</option> 
         <option value="3">Hey!</option> 
      </select>  
   </body>
</html>

Related Tutorials