Industry guru Dave Taylor offers free tech support on a wide variety of technical and business topics, including HTML, Apple iPhone, online advertising, Cascading Style Sheets, Web design, management, Unix, Linux, search engine optimization, online dating, Mac OS X, shell script programming and Microsoft Windows.

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.


Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon    
Categorized: HTML and CSS   (Article 4312)
Tagged:
Previous: How do I split my Typepad entries into two parts?
Next: Can I get Plaxo spam?

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

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

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

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











Remember personal info?


Please note that I will never send you any unsolicited commercial 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.









Uniblue: Free Virus Scan

Follow me on Twitter @DaveTaylor

Search
Find just the answers you seek from among our 2300+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Book Links
© 2002 - 2009 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.