Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


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.

More Useful HTML, JavaScript and Web Site Programming Articles:
✔   How to Create Predefined Google Image Search Links?
Thanks for the Amazon URL [see Creating Amazon Search Links]. That worked beautifully. In fact, I sent you $5.00 for coffee in thanks....
✔   Can I embed a Facebook search box on my blog site?
I've seen your articles about how to add a Twitter or Google search box on a Web page, but I have a tougher...
✔   Can I use CSS for drop shadows on my blog?
I want to give my site a bit of a facelift and add some neat graphical elements. One of which is drop shadows....
✔   How can I embed interactive photo panoramas on my site/blog?
I read through your blog entry about how to take panoramic photos with iOS 6 and an iPhone 5 and got enthused. I've...
✔   How can I create a Twitter search URL shortcut?
I'd like to add a few Twitter search links to my Web site. Is that possible, or does Twitter prohibit this sort of...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  




Categorized: HTML, JavaScript and Web Site Programming   (Article 4312, Written by )
Tagged: html, searching, site programming, site search
Previous: How do I split my Typepad entries into two parts?
Next: Can I get Plaxo spam?




Reader Comments To Date: 8

Gary said, on December 6, 2007 7:12 AM:

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?

Dave Taylor said, on December 6, 2007 10:08 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?

Hennie Henrico said, on March 14, 2009 6:53 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 ?

Hennie Henrico said, on March 14, 2009 6:59 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.

keef said, on May 15, 2009 2:59 PM:

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

keef said, on May 15, 2009 3:06 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

Amy said, on February 26, 2010 12:37 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

M Yakub said, on June 15, 2010 2:16 AM:

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

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, Dave, for all your helpful information by buying you a cup of coffee!

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











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 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. Further, 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. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.