When you have just started blogging and have only a few posts, it is easy for users to locate content in your blog. If you have been blogging for quite some time, it is wise to put a search box in your blog. This will allow people to search keywords and reach posts in your blog. Where do you get a search box for your site?

Heh listen up, building a search box is just a couple of minutes away. and one of the best too, because we will make it powered by google. (:-))

Lets look why you need your own  search box? Simply because, you can customize your box to fit to the look and feel of your blog or website.

What do we need for a search box, firstly a text box and a submit button, both packed in a form.

1. Set the form’s action parameter to “google.com/search”

2. Set the method to get. Why? You must remember that google search shows your keywords in the address bar. That should remind you that, it operates on GET and not POST.

3. You may want to include or exclude an additional radio button asking users to search in the website or in the web.  In this case, put up a radio button, with name as sitesearch and value as your domain name.We will trick the other radio button with no name. You must remember to exclude http:// and even www from your domain name.

Here is the actual snippet of code.

<FORM METHOD=’GET’ ACTION=”http://www.google.com/search”>
<INPUT TYPE=”text” NAME=”q” value = “Type and hit..” onFocus = “this.value = ” “; size = ‘30′>
<INPUT TYPE=”radio” NAME=”">the ocean
<INPUT TYPE=”radio” NAME=”sitesearch” value = “codeinsane.com”>this blog
<INPUT TYPE=”submit”>
</FORM>

4. If you want users to search only in your blog, use a hidden field, with name as sitesearch and value as your domain name.

<input type = “hidden” name = “sitesearch” value = “codeinsane.com”>

5. Alright, this was simple, lets expand this. Use ajax and show up the results in a small frame perhaps. That will be in a separate article, later.

Extra  Tip : Put your search box right on top and probably on the right top corner.