Searchbox: jQuery live search plugin
Ah, the infamous live search. Often overused, but handy nonetheless. A project I’m currently working on has several places where a live search is exactly the right solution. I looked into the existing options, but wasn’t quite satisfied with the implementations. Since it’s an easy enough thing to do, I wrote a plugin for it. It’s called searchbox and can be found on github.
Usage
In it’s basic form (if you’re happy with the default configuration):
1 |
$('input.search').searchbox()
|
Or you can configure a few things:
1 2 3 4 5 6 7 |
$('input.search').searchbox({
url: '/your/search/url',
param: 'q',
dom_id: '#thumbnails',
delay: 250,
loading_css: '#spinner'
})
|
See the implementation (or the README) for the defaults.
Hooks
There are currently three places you can hook into the plugin.
- initialization:
init.searchbox - before the search is submitted:
before.searchbox - after the search is completed:
after.searchbox
These events get triggered at the right time and place within the plugin, and don’t do anything by default. But if you need to execute some special code in one of those three situations, you just have to bind a function to any one of those events. For example, to execute some code after the search:
1 2 3 |
$(document).bind('after.searchbox', function() {
$('a[rel=facebox]').unbind('click').facebox()
})
|
Feel free to fork and improve.

mark Wednesday, 04 Aug, 2010 Posted at 07:31PM
do you have demo page for this?
Ryan Wednesday, 04 Aug, 2010 Posted at 08:30PM
Mark—
Sorry, no I don’t have a demo page. The idea is to have the URL hit the server and return some data, and I didn’t want to always have to have that URL working for a demo page.
But it really is pretty simple. The README has the goodies, which I’m sure you’ve seen already.
Let me know if you have any questions/issues getting it to work, I’d be happy to help out if I can.
Gregg Turnbull Friday, 28 Jan, 2011 Posted at 02:25PM
I have been able to get an individual search box to work without fail, but when I add more than one, it appears it reads the last parameters every time searchbox is called. Am I missing something? left a message on github with code but can’t post that same code in the comment here. Thanks.
Ryan Tuesday, 01 Feb, 2011 Posted at 11:49PM
@Gregg -
Hey, sorry to leave you hanging, I’ve had a lot going on lately. That’s odd behavior. I’ve not needed it for multiple search boxes on the same page, so I can’t say. If I get time in the next day or two I’ll take a look.
tjeden Monday, 07 Feb, 2011 Posted at 11:27AM
@Greg
This plugin works only with one parameter. I’ve made a quick fork: https://github.com/tjeden/searchbox and now it serialize given form instead of one input field. I will work on it (i.e. this livesearch won’t work on select_fields) also I want to allow some customization (to choose wanted fields). Please give me info if you would like some other bahaviour.