Get last selected listbox item in javascript - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select

Description

Get last selected listbox item in javascript

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 w  w .jav  a 2  s. co 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