Change select option with var change - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

Change select option with var change

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <select id="select1" onchange="jsFunction(this)"> 
         <option value="1">1</option> 
         <option value="2">2</option> 
         <option value="3">3</option> 
      </select> 
      <script>
document.getElementById('select1').value = 2;
function jsFunction(select){
  console.log(select.value);
}

      </script>  
   </body>//from w w w  .j a  va2  s  .  c om
</html>

Related Tutorials