title: How to set the default option for SELECT Tag and how to get the Index of the selected option?
body: <p>I would like to have a code in HTML and JavaScript that process SELECT and OPTION Elements </p>
  
  <pre><code>&lt;select&gt;
      &lt;option&gt;
      &lt;/option&gt;
      &lt;option&gt;
      &lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>How I can get the Index of the selected option and then get the value of this index?</p>
  
  <p>How can I make 2010 as the default option visual for users in the select tag existing in the form in a web page?</p>
  
  <p>My code looks like that :</p>
  
  <pre><code>&lt;select id="SelectYear" name="SelectYear" size="1"&gt;  
      &lt;script type="text/javascript"&gt;
          var startyear = "1950";
          var endyear   = "2020";
          for(var k=startyear; k&lt;=endyear; k++ ) document.write("&lt;option value="+k+"&gt;"+k+"&lt;/option&gt;");
      &lt;/script&gt;   
  &lt;/select&gt;
  </code></pre>
  
  <p>I tried many expressions to get that index even I know it may give a different thing like:</p>
  
  <pre><code>var vIndex = document.getElementById('SelectYear').selectedIndex;    
  var vIndex = document.getElementById('SelectYear').selectedIndex.value;    
  var vIndex = document.getElementById('SelectYear').selectedIndex.text;  
  var vIndex = document.getElementById('SelectYear').options[document.getElementById('SelectYear').selectedIndex];  
  var vIndex = document.getElementById('SelectYear').options[document.getElementById('SelectYear').selectedIndex].value;  
  var vIndex = document.getElementById('SelectYear').options[document.getElementById('SelectYear').selectedIndex].text;
  </code></pre>
  
  <p>My workaround solution is to put the index static like:</p>
  
  <pre><code>document.getElementById('SelectYear').selectedIndex = 60 ;
  </code></pre>
  
  <p>But if I do not know the exact index or the index is changed according to the changes happended in the SELECT elements due to database update or manual edit?</p>