Handle <select> option value changed event - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select

Description

Handle <select> option value changed event

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <select id="example"> 
         <option value="1">1st</option> 
         <option value="2">2nd</option> 
      </select> 
      <script type="text/javascript">
document.getElementById("example").onchange = function() {
    var selected = this.value;/*from   w  ww .j a v  a  2 s .c  om*/
    console.log(selected);
}

      </script>  
   </body>
</html>

Related Tutorials