Using JavaScript functions with forms

         Search engine to use:    Search for: 

Using JavaScript functions you can link to different search engines from the same input form. Here's how it's done:

<form name="Searchform">
  Search engine to use:
  <select name="selection">
    <option value="Google">Google</option>
    <option value="AllTheWeb">AllTheWeb</option>
    <option value="AltaVista">Altavista</option>
    <option value="Excite">Excite</option>
    <option value="GO.com">GO.com</option>
    <option value="HotBot">HotBot</option>
    <option value="Lycos">Lycos</option>
    <option value="Search.com">Search.com</option>
  </select>
  Search for:
  <input type="text" name="searchtext">
  <input type="button" name="DoSearch" value="Search" onClick="Search()">
</form>

// Go to the selected search engine with the input text
function Search() {
    var site = document.Searchform.selection[document.Searchform.selection.selectedIndex].value;
    var stext = document.Searchform.searchtext.value;
    var len = stext.length;

    // If string is phrase (bracketed by quotes) replace quotes with %22
    if ((stext[0] == '"') & (stext[len-1] == '"')) {
      var newstext = "%22" + stext.substring(1,len-1) + "%22";
      stext = newstext;
      len = len + 4;
    }

    // Replace embedded blanks with + signs
    for (i=1; i<len; i++) {
      if (stext[i] == " ") {
        var newstext = stext.substring(0,i) + "+" + stext.substring(i+1,len);
        stext = newstext;
      }
    }

    // Format the URL and search string based on the selected search engine
    // Search engines change these sometimes and they must be modified
    if (site == "Google") {var urlString = "http://www.google.com/search?q=" + stext + "&meta=lr%3D%26hl%3Den&btnG=Google+Search"};
    if (site == "AllTheWeb") {var urlString = "http://www.alltheweb.com/search?cat=web&cs=iso-8859-1&l=any&q=" + stext};
    if (site == "AltaVista") {var urlString = "http://www.altavista.com/web/results?q=" + stext + "&search.x=66&search.y=9"};
    if (site == "Excite") {var urlString = "http://search.excite.com/search.gw?search=" + stext};
    if (site == "GO.com") {var urlString = "http://srch.overture.com/d/search/p/go/?Partner=go_home&Keywords=" + stext + "&Go=Search"};
    if (site == "HotBot") {var urlString = "http://hotbot.lycos.com/?MT=" + stext + "&SM=MC&DV=0&LG=any&DC=10&DE=2&x=44&y=5"};
    if (site == "Lycos") {var urlString = "http://search.lycos.com/default.asp?lpv=1&loc=searchbox&query=" + stext + "&x=35&y=9"};
    if (site == "Search.com") {var urlString = "http://www.search.com/search?channel=1&tag=st.se.fd..sch&q=" + stext};

    location = urlString;  // Go use the search engine
}