Get text value from <option> tag - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

Get text value from <option> tag

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <select onchange="getme(this)"> 
         <option value="1">dog</option> 
         <option value="2">cat</option> 
         <option value="3">bird</option> 
      </select> 
      <script>
function getme(e){//from   ww  w .  j  a  v a 2 s.co  m
console.log(e.options[e.selectedIndex].text);
}
      </script>  
   </body>
</html>

Related Tutorials