get a selected option's value - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

get a selected option's value

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function getValue() {//from  w w w.j a v  a  2 s . c om
    var val = document.getElementById("test").value;
    console.log(val);
}

      </script> 
   </head> 
   <body> 
      <select id="test"> 
         <option value="1">first</option> 
         <option value="2">second</option> 
      </select> 
      <input type="button" onclick="getValue();" value="get value">  
   </body>
</html>

Related Tutorials