Handle change event on <select> element - Javascript DOM

Javascript examples for DOM:Event

Description

Handle change event on <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">
function myFun(sel)/*from w ww .  java2  s.c o  m*/
{
    console.log(sel.options[sel.selectedIndex].value);
}

      </script> 
   </head> 
   <body> 
      <select multiple onchange="myFun(this);"> 
         <option value="volvo">Volvo</option> 
         <option value="saab">Saab</option> 
         <option value="opel">Opel</option> 
         <option value="audi">Audi</option> 
      </select>  
   </body>
</html>

Related Tutorials