Home : Internet : JavaScript : Multiple SearchMultiple Search : Variation 2

Multi-Search Form—Variation 2

This form is a variation of our generic multi-search form. In this case we need to have two options:

  1. A standard search URL in the form http://www.google.com/search?q=KEYWORD (we've used Google for this example but it works for any search engine with the same format).
  2. A search URL with additional strings before and after the keyword, like so: http://www.example.com/first_stringKEYWORDlast_string

This is how it will look, although you can obviously customize it:

Search:    For: 

 

The code below goes in the document head (customize the red text for your application):

<script type="text/javascript">
function dosearch() {
  var rest_of_URL = "last_string";
  var sf = document.searchform;
  var se = sf.sengines.options[sf.sengines.selectedIndex].value;
  var kw = sf.searchterms.value;
  var submitto = se + kw;
  if (se == "http://www.example.com/first_string") { submitto += rest_of_URL; }
  window.location.href = submitto;
}
</script>

The code below is for the search form in the web page:

<form name="searchform" onSubmit="return dosearch(); return false;">
Search:&nbsp;
<select name="sengines">
<option value="http://www.example.com/first_string">Catalog</option>
<option value="http://www.google.com/search?q=">Google</option>
</select>
&nbsp;&nbsp;For:&nbsp;
<input name="searchterms" type="text" value="">
<input type="submit" name="SearchSubmit" value="Search">
</form>

Related forum thread: www.mediacollege.com/forum/showthread.php?9037-Multiple-search-question