View Full Version : Help with New Window + Search Function

10-06-2005, 03:05 PM

I've got this javascript search engine working on a site.

The problem is I don't know much javascript, but have managed to get it to work. BUT I need the search to open in a new window.

Trying various coding to open a window, I've managed to get a blank window to come up, but it's blank! I can't get the search results to appear in the new window. I've found no help on the web for getting onclick to do two things at once. :confused:

If anyone could help (in baby talk for a javascript newbie..maybe just add to this code in bold or red or something?), I'd surely appreciate it.

The search engine code is:


<script language="JavaScript" type="text/javascript">



function startSearch(){searchString = document.searchForm.searchText.value;if(searchString != ""){searchEngine = document.searchForm.whichEngine.selectedIndex + 1;finalSearchString = "";

if(searchEngine == 1){finalSearchString = "http://www.altavista.com/cgi-bin/query?pg=q&what=web&q=" + searchString;}

if(searchEngine == 2){finalSearchString = "http://www.galaxy.com/cgi-bin/query?keys=" + searchString;}

if(searchEngine == 3){finalSearchString = "http://www.google.com/search?q=" + searchString + "&btnG=Google+Search";}

if(searchEngine == 4){finalSearchString = "http://www.lycos.com/cgi-bin/pursuit?query=" + searchString + "&backlink=639";}

if(searchEngine == 5){finalSearchString = "http://search.yahoo.com/bin/search?p=" + searchString;}

if(searchEngine == 18){finalSearchString = "http://de.search.yahoo.com/search/de?p=" + searchString;}location.href = finalSearchString;}}// -->



<form name="searchForm">

<table width="200" border cellpadding=3 cellspacing=2 bgcolor="#ebebeb">

<td width="75" bgcolor=lightblue><font size=1 face="Verdana, Arial, sans-serif">Search<br> for:<br>
<td width="100" bgcolor=lightblue><font size=1 face="Verdana, Arial, sans-serif">Search<br> from:
<td width="25" bgcolor=lightblue><font size=1 face="Verdana, Arial, sans-serif">&nbsp;
<!--<td width="100" bgcolor=lightblue><font size=1 face="Verdana, Arial, sans-serif">&nbsp;-->

<td bgcolor=navajowhite><input style="background: dddddd" size="2" name="searchText" type="text"><!--<br><p>-->
<td bgcolor=navajowhite>
<select width="2" name="whichEngine"

<option >Altavista</option>


<option selected>Google</option>



<td bgcolor=navajowhite valign="bottom">&nbsp;<br>
<input type="button" value="Go" onClick="startSearch()">


Thanks very much.

11-02-2005, 09:34 PM
To make results open in NEW window, replace:

(use find function)

location.href = finalSearchString;}}// -->


NewWin = window.open(finalSearchString);}}// -->