Click to See Complete Forum and Search --> : Altering Search Engine Script
Jenn603
01-27-2003, 03:04 PM
I found a script which allows the user to choose which search engine to use. Script is at http://htmlgoodies.earthweb.com/stips/scripttip42script.html .
I would like to be able to choose the search engine by clicking on an image, instead of using checkboxes (or radio buttons or a drop down menu). Could someone help me with this?
Also, would it be possible to send the user to the selected search engine's homepage as a default, if there is no text entered in the textbox?
Jenn
jdavia
01-27-2003, 10:04 PM
Answer to the first question
<A HREF="http://theAddress.com"><img src="your.gif" width="100"height="100"BORDER=0></A>
Answer to the second part:
The default is there has to be some action to take place for it to happen. You shouldn't try to force anything on someone.
Also, would it be possible to send the user to the selected search engine's homepage as a default, if there is no text entered in the textbox?
What do you think will happen if it had an action. Every time the page loads and no text is entered, on closing, would be taken there even if they never see the text box.
Jenn603
01-28-2003, 02:47 AM
jdavia,
Thank you for replying to my post, but I do not think you understood my questions.
The script at http://htmlgoodies.earthweb.com/stips/scripttip42script.html
lets the user type a search term in a textbox and then select a search engine to use by clicking a checkbox. I want to do the same thing, only instead of selecting the search engine with a checkbox, the user would select an image for that search engine.
For example...
With the script as it is, the user types the search term "chair" into the textbox. Then he selects the checkbox for Yahoo! and is sent to Yahoo's search results page for "chair". If he had selected the checkbox for Google, he would have been sent to Google's search results page for "chair".
I want to alter the script so that when the user types the search term "chair" in the textbox, he then clicks on an IMAGE for Yahoo! and is sent to Yahoo's search results page for "chair".
If the user clicks on one of these images without first typing a search term in the textbox, I would like him to go to that search engine's homepage, instead of to a search result page that says "Please enter one or more search terms in the search box." pr "Please check your spelling." This is what I meant by a default. There is no "action" unless the user clicks on an image.
I hope this explaination is better.
Can you (or anyone else) help me with this?
jdavia
01-28-2003, 04:15 AM
I don't think that is possible either. but you can do this instead of a textbox. You will type in the keyword at the search engine site.
(Yes I know it is half way to what you want. Maybe someone will jump in).
<A HREF="http://search.yahoo.com/search?p=">
<img align=middle src="imageA.gif" width="30"height="50"BORDER=0>Yahoo</A> <BR>
<A HREF="http://www.altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=.&q=">
<img align=middle src="imageB.gif"width="30"height="50"BORDER=0>Altavista</A> <BR>
<A HREF="http://www.webcrawler.com/cgi-bin/WebQuery?searchText=">
<img align=middle src="imageC.gif" width="30"height="50"BORDER=0>WebCrawler</A><BR>
<A HREF="http://www.excite.com/search.gw?trace=a&search=">
<img align=middle src="imageA.gif" width="30"height="50"BORDER=0>Excite</A> <BR>
<A HREF="http://www.lycos.com/cgi-bin/pursuit?query=">
<img align=middle src="imageB.gif"width="30"height="50"BORDER=0>Lycos</A>
Dan Drillich
01-28-2003, 09:08 AM
Jenn,
Here is a modified version that should do what you asked for.
Just plug the proper images at the image tags.
Cheers,
Dan
<SCRIPT LANGUAGE="JavaScript">
function wordsplit(items)
{
var charect = "";
for (var n = 1 ; n <= items.length ; n++)
{
if (items.substring(n-1,n) == " ")
{ charect+="+"; }
else
{ charect+=items.substring(n-1,n); }
}
return charect;
}
var yahoo = new Object();
yahoo.search = "http://search.yahoo.com/search?p=";
yahoo.home = "http://www.yahoo.com";
var altavista = new Object();
altavista.search = "http://www.altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=.&q=";
altavista.home = "http://www.altavista.com";
var webcrawler = new Object();
webcrawler.search = "http://www.webcrawler.com/cgi-bin/WebQuery?searchText=";
webcrawler.home = "http://www.webcrawler.com";
var lycos = new Object();
lycos.search = "http://www.lycos.com/cgi-bin/pursuit?query=";
lycos.home = "http://www.lycos.com";
var excite = new Object();
excite.search = "http://www.excite.com/search.gw?trace=a&search=";
excite.home = "http://www.excite.com";
function search(site)
{
var keywords=document.searching.query.value;
key=wordsplit(keywords);
var search;
switch(site) {
case 'Yahoo':
if (key == "") {
search = yahoo.home;
} else {
search = yahoo.search+=key;
}
wind=window.open(search,"newwindow1","width=700,height=200,scrollbars=yes");
break;
case 'altavista':
if (key == "") {
search = altavista.home;
} else {
search = altavista.search+=key;
}
wind=window.open(search,"newwindow1","width=700,height=200,scrollbars=yes");
break;
case 'webcrawler':
if (key == "") {
search = webcrawler.home;
} else {
search = webcrawler.search+=key;
}
wind=window.open(search,"newwindow1","width=700,height=200,scrollbars=yes");
break;
case 'lycos':
if (key == "") {
search = lycos.home;
} else {
search = lycos.search+=key;
}
wind=window.open(search,"newwindow1","width=700,height=200,scrollbars=yes");
break;
case 'excite':
if (key == "") {
search = excite.home;
} else {
search = excite.search+=key;
}
wind=window.open(search,"newwindow1","width=700,height=200,scrollbars=yes");
break;
default:
break;
}
}
</SCRIPT>
<FORM NAME="searching">
Enter the Key word : <INPUT TYPE="text" NAME="query" SIZE=20><BR><BR>
<b>Select the Search Engine(s):</b><br>
<input type="image" src="" width="31" height="15" border="0" alt="Yahoo"
onclick="search('Yahoo');"><br><br>
<input type="image" src="" width="31" height="15" border="0" alt="altavista"
onclick="search('altavista');"><br><br>
<input type="image" src="" width="31" height="15" border="0" alt="webcrawler"
onclick="search('webcrawler');"><br><br>
<input type="image" src="" width="31" height="15" border="0" alt="excite"
onclick="search('excite');"><br><br>
<input type="image" src="" width="31" height="15" border="0" alt="lycos"
onclick="search('lycos');"><br><br>
</FORM>
jdavia
01-28-2003, 01:34 PM
Dan Drillich,
Thanks for filling in the gaps. I will use that also. I added the name of the search engine to identify it for jenn603 if it is wanted.
<input type="image" src="SubmitA.gif" width="31" height="15" border="0" alt="Yahoo" onclick="search('Yahoo');"> Yahoo<br><br>
Jenn603
01-30-2003, 02:56 AM
Dan and jdavia,
Thank you both!
I will try it out and let you know if I have any trouble.
:)
Jenn