Check value from <option> - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

Check value from <option>

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from w w w  . ja  va2s  .  c  o m*/
var elements = document.getElementsByTagName('option');
for (i=0;i<elements.length;i++) {
  if(elements[i].value == '48') {
    elements[i].selected = true;
  }
}
    }

      </script> 
   </head> 
   <body> 
      <select> 
         <option value="50">50&nbsp;-&nbsp;State</option> 
         <option value="48">48&nbsp;-&nbsp;State</option> 
      </select>  
   </body>
</html>

Related Tutorials