Free tech support / small logo


How do I build a multi-site search box?

If I have a Google web search form placed in my site, how can I set it up so that there is one input box (for the web search) but two submit buttons - one for a web 'text' search, and one for a google image search? Is that even doable??


Dave's Answer:

That's not terribly difficult to accomplish, actually, and it's quite informative for people seeking to experiment with feeding a search pattern to more than one search engine too.

First off, here's the form at work:


And here's the source for that form, in XHTML:

<form target="_blank" name="googleForm" method="get"
  action="http://www.google.com" style="border:1px solid black;padding:8px;">
<input type="text" name="q" size="40" maxlength="255" value="" /><br />
<input type="submit" value="Google Search!"
  onClick="document.googleForm.action='http://www.google.com/search';" />
<input type="submit" value="Google Images!"
  onClick="document.googleForm.action='http://www.google.com/images';">
</form>

See how that works? All you need to do is change the action value of the form through a tricky little bit of JavaScript.

There's no reason you couldn't use this very same techinque to have a search engine box on your site, for example, that could send the same query to a number of different search engines (though you need to ensure that they all expect the search term to have the same variable name).

Hope this helps!

My thanks to Jason M. Hurst Frye for his help with this snippet of HTML.




Categorized: HTML and CSS   (Article 4312, Written by )
Tagged:
Previous: How do I split my Typepad entries into two parts?
Next: Can I get Plaxo spam?




Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments

Hi

Great Post!
Is there any way I can get two text boxes as input or 2 drop downs as input and then search the site using the concatenation of the two inputs?

Posted by: Gary at December 6, 2007 7:12 AM

Gary, yes you could: you'd need to stitch them together with some Javascript tied to the "onSubmit" event (you'd add that to the FORM tag). Why do you want to do it that way, though?

Posted by: Dave Taylor at December 6, 2007 10:08 AM

Hi Dave.

Ive copied and pasted this into my html but when I do a google search from there, i google page that says the page was not found or the results where not found. any advise ?

Posted by: Hennie Henrico at March 14, 2009 6:53 AM

Ok, some more info on my previous question. When I type anything into the google search bar on my web page, a google page opens up with the following message: The page - www.google.com/?q=protea - does not exist. When I then click the search button on that page, I get the results I wanted. Have I done something wrong ? is it because i am running html in stead of xhtml ? these tings are so confusing for a first timer like me.

Posted by: Hennie Henrico at March 14, 2009 6:59 AM

Hi Dave,
Great info - many thanks.
Is there any way I can have a single text/keyword input box and search button, but have a list of sites to search below - each with their own individual checkbox?
This would be a useful tool for those wishing to look for specific technical info within a limited number of specialist sites.
Also, is there any scope for separate lists under their own subheadings?

Let's say, set out like this (X = checkbox):

KEYWORDINPUTBOX SEARCHBUTTON

X my site

SUBHEADING 1
X another site 1
X another site 2
X another site 3

SUBHEADING 2
X another site 4
X another site 5
X another site 6

... and so on.

Cheers,
keef

Posted by: keef at May 15, 2009 2:59 PM

... oh, by the way.
I forgot to ask - is there much leeway for creative positioning of the various elements over a page or, at least, division or table - say, having a keyword input box near the top left and the search button or checkboxes way over somewhere else?

Cheers,
k

Posted by: keef at May 15, 2009 3:06 PM

Dave,
I work at a community hospital. We subscribe to 4 ebook vendors for medical ebooks. All of them are IP authenticated. I'd like to set up a search to search them all simultaneously. I tried buildasearch.com. It looks promising. I can add up to 15 sites. However it requires IE 8 or higher and I'm not getting good results. Any suggestions of another site to build a taylored search or troubleshoot buildasearch.com?
Thanx in advance,
Amy

Posted by: Amy at February 26, 2010 12:37 PM

Hello and greetings,
Your form to add google search to website is simple and great, thanks indeed.
Please tell me how to add more than one website to 'search this site only' to do search for websites thus added.
Muhammed

Posted by: M Yakub at June 15, 2010 2:16 AM

I have something to say, now that you mention it, but ...
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!


© 2002 - 2012 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.