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 can I add an Amazon search box to my web page?

You have shown how to add eBay, Google, and Technorati searches to your own web page. Is it possible to add an Amazon search to your page, and how would you do it?


Dave's Answer:

Of course it's possible! Everything is possible on the Web. :-)

My first step is to go to Amazon.com and do a search, just to see the resultant URL. In this case, a search for Harry Potter reveals this scary URL:

http://www.amazon.com/s/ref=nb_ss_gw/102-1882688-6100927?initialSearch=1&url=search-alias%3Daps& field-keywords=harry+potter&Go.x=6&Go.y=15&Go=Go

Way more than I ever want to explore, but I can't help be curious what happens if I clean up everything except the actual search pattern, producing the following shorter URL:

http://www.amazon.com/s/ref=nb_ss_gw/102-1882688-6100927?i field-keywords=harry+potter

Ulp. Cut out too much and it doesn't work. Instead, let's work on getting rid of that ugly ref value. This URL does work:

http://www.amazon.com/s/?url=search-alias%3Daps&field-keywords=harry+potter&Go.x=0&Go.y=0

a tiny bit more experimentation and we learn that a slightly shorter URL will work too:

http://www.amazon.com/s/?url=search-alias%3Daps&field-keywords=harry+potter&Go=Go

Now we can reverse engineer the URL and turn it into a form. Everything before the "?" is the action of the form, and everything after is in name=value form, with those pairs separated by an "&" symbol. Tiny additional nuance: the "%3D" in the URL is an encoded "=" symbol, so we'll want to change that back as part of the code writing process. This means that the following should work:

<form method="get" action="http://www.amazon.com/s/">
<input type="hidden" name="url" value="search-alias=aps" />
Search Amazon: <input type="text" name="field-keywords" />
<input type="submit" name="Go" value="Go" />
</form>

Sure enough, it does. Try it here:

   

Search Amazon:

I admit, it's not the prettiest form we could create, but functionality-wise, I hope you can see how as with the other search boxes I've duplicated here, this is more a detective job than an HTML coding job.

Tip: Want to have the search results open in a new window? Add the attribute target="new" to the FORM line.



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon    

Subscribe!

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

Comments

Thank you for this tutorial, I have made a You Tube and a few other search boxes for my site because of it. some searches are quite difficult but it is a fun challange.

Posted by: kelly hogg at August 10, 2007 3:05 PM

What if I want the search to only search a certain keyword, Example "Honda Parts" ?

Posted by: Bryan at September 28, 2007 9:39 AM

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.