title: Adding select menu default value via JS?
body: <p>i'm developing a meta search engine website, <a href="http://soogle.net/" rel="nofollow noreferrer">Soogle</a> and i've used JS to populate select menu..</p>
  
  <p>Now, after the page is loaded none of engines is loaded by default, user needs to select it on his own or [TAB] to it..</p>
  
  <p>Is there a possibility to preselect one value from the menu via JS after the page loads?</p>
  
  <p>This is the code:</p>
  
  <p>Javascript:</p>
  
  <pre><code>// SEARCH FORM INIT
  function addOptions(){
      var sel=document.searchForm.whichEngine;
      for(var i=0,l=arr.length;i&lt;l;i++){
          sel.options[i]=new Option(arr[i][0], i);
      }
  }
  
  function startSearch(){
      var searchString=document.searchForm.searchText.value;
      if(searchString.replace(/\s+/g,"").length &gt; 0){
          var searchEngine=document.searchForm.whichEngine.selectedIndex,
              finalSearchString=arr[searchEngine][1]+searchString;
          window.location=finalSearchString;
      }
      return false;
  }
  function checkKey(e){
      var key = e.which ? e.which : event.keyCode;
      if(key === 13){
          return startSearch();
      }
  }
  
  // SEARCH ENGINES INIT
  var arr = [
      ["Web", "http://www.google.com/search?q="],
      ["Images", "http://images.google.com/images?q="],
      ["Knowledge","http://en.wikipedia.org/wiki/Special:Search?search="],
      ["Videos","http://www.youtube.com/results?search_query="],
      ["Movies", "http://www.imdb.com/find?q="],
      ["Torrents", "http://thepiratebay.org/search/"]
  ];
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;body onload="addOptions();document.forms.searchForm.searchText.focus()"&gt;
  
  &lt;div id="wrapper"&gt;
  &lt;div id="logo"&gt;&lt;/div&gt;
  
  &lt;form name="searchForm" method="POST" action="javascript:void(0)"&gt;
  &lt;input name="searchText" type="text" onkeypress="checkKey(event);"/&gt;
  &lt;span id="color"&gt;&lt;/span&gt;
  &lt;select tabindex="1" name="whichEngine" selected="Web"&gt;&lt;/select&gt;
  &lt;br /&gt;
  &lt;input tabindex="2" type="button" onClick="return startSearch()" value="Search"/&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  </code></pre>