PDA

View Full Version : How do you make 1 search box with many choices?



sartajc
11-26-2006, 01:57 AM
The search form on this forum can search both the vbulletin and google depending on what you click on.

I want to do this too with my site.

What script did you use to do this?

Tristan S.S.
11-26-2006, 02:00 AM
Here. Hope you enjoy. Just change the details to what you want.


<!-- SiteSearch Google -->
<FORM method=GET action="http://www.google.com/search">
<input type=hidden name=ie value=UTF-8>
<input type=hidden name=oe value=UTF-8>
<TABLE bgcolor="#FFFFFF"><tr><td>
<A HREF="http://www.google.com/">
<IMG SRC="http://www.google.com/logos/Logo_40wht.gif"
border="0" ALT="Google"></A>
</td>
<td>
<INPUT TYPE=text name=q size=31 maxlength=255 value="">
<INPUT type=submit name=btnG VALUE="Google Search">
<font size=-1>
<input type=hidden name=domains value="YOUR DOMAIN NAME"><br><input type=radio name=sitesearch value=""> WWW <input type=radio name=sitesearch value="YOUR DOMAIN NAME" checked> YOUR DOMAIN NAME <br>
</font>
</td></tr></TABLE>
</FORM>
<!-- SiteSearch Google -->

sartajc
11-26-2006, 08:52 PM
No, i dont want google sitesearch. I think you misunderstood me.

I want ONE search form to be able to have many choices on what you want to search. For example, what this site has. You can choose to search with the vBulletin Search engine or the Google sitesearch engine.

How do you do this?

thetestingsite
11-26-2006, 09:37 PM
Try this:



<form id="searchForm" action="" method="" onSubmit="sitesearch(this)">

<b>Search:</b><br />

<input id="hiddenquery" type="hidden" name="q">
<input id="hiddenqueryinternal" type="hidden" name="query">
<input type="hidden" name="do" value="process">
<input type="hidden" name="showposts" value="0">
<input type="hidden" name="quicksearch" value="1">
<input type="hidden" name="s" value="">

<input name="searchfor" type="text" style="width: 310px;"> <input type="submit" value="Search" /><br>

<div style="font: bold 11px Verdana;"><input name="se" type="radio" checked>Site Search <input name="se" type="radio">Try Google Instead
</div>

<script type="text/javascript">

function switchaction(curobj, index){
if (index==0){ //if internal
document.getElementById("searchForm").action="search.php"
document.getElementById("searchForm").method="post"
document.getElementById("hiddenqueryinternal").value=curobj.searchfor.value
document.getElementById("hiddenquery").value=""
}
else if (index==1){ //if Google search
document.getElementById("searchForm").action="http://www.google.com/search"
document.getElementById("searchForm").method="get"
document.getElementById("hiddenquery").value=curobj.searchfor.value
document.getElementById("hiddenqueryinternal").value=""
}
}

function sitesearch(curobj){
for (var i=0; i< document.getElementById("searchForm").se.length; i++){ //loop through radio to see which is checked
if (document.getElementById("searchForm").se[i].checked==true)
switchaction(curobj, i)
}
}


</script>


just place that where you want it to appear on your page.

mwinter
11-27-2006, 12:36 AM
I want ONE search form to be able to have many choices on what you want to search. For example, what this site has. You can choose to search with the vBulletin Search engine or the Google sitesearch engine.

How do you do this?

The best way would be allow the server to decide, sending a redirect to Google if the user chose that option.

The engine choice would be submitted along with the search terms to the server as normal. If the user chose to use Google, the query would be constructed server-side, and a HTTP redirect would be issued, sending the user to Google. If the built-in search engine was chosen, then the redirect would be skipped and normal processing would resume.

Exactly how one would go about implementing that depends on what server-side programming language you'd want to use (and would be best addressed in the appropriate forum).

Mike

sartajc
11-27-2006, 11:09 AM
The best way would be allow the server to decide, sending a redirect to Google if the user chose that option.

The engine choice would be submitted along with the search terms to the server as normal. If the user chose to use Google, the query would be constructed server-side, and a HTTP redirect would be issued, sending the user to Google. If the built-in search engine was chosen, then the redirect would be skipped and normal processing would resume.

Exactly how one would go about implementing that depends on what server-side programming language you'd want to use (and would be best addressed in the appropriate forum).

Mike
ummm, i want more than just the internal search and google. i wanted to be able to choose search site, arcade, google, blogs, and others.

see my site: http://muslimonline.org

sartajc
11-27-2006, 11:10 AM
Try this:



<form id="searchForm" action="" method="" onSubmit="sitesearch(this)">

<b>Search:</b><br />

<input id="hiddenquery" type="hidden" name="q">
<input id="hiddenqueryinternal" type="hidden" name="query">
<input type="hidden" name="do" value="process">
<input type="hidden" name="showposts" value="0">
<input type="hidden" name="quicksearch" value="1">
<input type="hidden" name="s" value="">

<input name="searchfor" type="text" style="width: 310px;"> <input type="submit" value="Search" /><br>

<div style="font: bold 11px Verdana;"><input name="se" type="radio" checked>Site Search <input name="se" type="radio">Try Google Instead
</div>

<script type="text/javascript">

function switchaction(curobj, index){
if (index==0){ //if internal
document.getElementById("searchForm").action="search.php"
document.getElementById("searchForm").method="post"
document.getElementById("hiddenqueryinternal").value=curobj.searchfor.value
document.getElementById("hiddenquery").value=""
}
else if (index==1){ //if Google search
document.getElementById("searchForm").action="http://www.google.com/search"
document.getElementById("searchForm").method="get"
document.getElementById("hiddenquery").value=curobj.searchfor.value
document.getElementById("hiddenqueryinternal").value=""
}
}

function sitesearch(curobj){
for (var i=0; i< document.getElementById("searchForm").se.length; i++){ //loop through radio to see which is checked
if (document.getElementById("searchForm").se[i].checked==true)
switchaction(curobj, i)
}
}


</script>


just place that where you want it to appear on your page.

The google one works, but i couldnt get the other ones to work. hmmm, is there any other way? maybe how myspace does it with ajax? (see http://myspace.com)

mwinter
11-27-2006, 02:11 PM
ummm, i want more than just the internal search and google. i wanted to be able to choose search site, arcade, google, blogs, and others.

So? That just means more radio buttons or select element options, and more if..else statements in the server-side code.

Mike

thetestingsite
11-27-2006, 05:24 PM
view http://thetestingsite.net/search.php and see if thats something along the lines of what you need.

sartajc
11-27-2006, 11:31 PM
view http://thetestingsite.net/search.php and see if thats something along the lines of what you need.
WOW, that search is amazing.

That is REALLY close to what I need. But heres what i need more specifically:

Search for {box here}
Where: {Dropdownmenu here}

The dropdown menu would contain:
Whole Site
Forum
Arcade
Quran
Hadith

This means that when you select something from the dropdown, the javascript or ajax will dynamically change the form action and input name.

Here is an example of 3 of the forms separately right now:


<tr>
<form action="http://muslimonline.org/index.php?act=Search&amp;CODE=01&amp;forums=all" method="post" target="_blank"></form>
<td align="right"><input name="keywords" onfocus="this.value=''" value="search..." size="20" type="text"></td>
<td align="left"><input class="button" value="Site" type="submit"></td>

</tr>

<tr>
<form action="http://www.muslimonline.org/index.php?act=quran&amp;op=search" method="post" target="_blank"></form>
<td align="right"><input name="query" onfocus="this.value=''" value="search..." size="20" type="text"></td>
<td align="left"><input class="button" value="Quran" type="submit"></td>

</tr>

<tr>
<form action="http://muslimonline.org/cgi-bin/hadith.cgi" method="post" target="_blank"></form>
<td align="right"><input onfocus="this.value=''" name="phrase" value="search..." size="20" type="text"></td>
<td align="left"><input class="button" value="Hadith" type="submit"> </td>


<td valign="middle" width="20">
&nbsp;&nbsp;
</td>
</tr>

thetestingsite
11-28-2006, 12:35 AM
Well that's seems simple enough. The way that mine is done is through a ton of PHP if and elseif statements,Let me see if I can make something up with the javascript and I'll post it on here.

thetestingsite
11-28-2006, 02:14 AM
so I was playing around with it in Javascript, but I'm not all the good at it and cannot get it to work as I planned. Maybe someone else on here can give it a try and post the code here to see maybe where I'm going wrong with it. I also tried with a simple PHP script, but for some reason it is not going through the GET method, only through POST. Sorry I couldn't have been more of a help to you.

sartajc
11-28-2006, 02:34 AM
I also tried with a simple PHP script, but for some reason it is not going through the GET method, only through POST. Sorry I couldn't have been more of a help to you.
No its ok, you've helped me so much already on this forum. Thanks a bunch :) .

Does anyone know how to make the javascript for this?

sartajc
12-04-2006, 10:38 PM
Bumpy Bump