Tuesday, January 11, 2011

Another Interface to My Custom Blog Search




I've written several posts about creating my own Blog search tool. Up until now I was only using it to bring up results for my various category links in the right sidebar. But now I want to also use it for the "site search" form, so you can type in a phrase to search for. Site search is the small blue form at the upper right corner. I'm going to leave the web search form alone.

I've already got the search mechanism, so this just take a bit of Javascript to handle the form submit event and run the custom search. Here's the code:

$('#searchthis').submit(function() {
     var q = $('#searchthis .sbox').attr('value');
        var href='http://tools.cssrule.com/search/?q='+q+'&title=Search Results:&callback=?';
        $.getJSON(href, process);
        return false;
    });

The first line sets up a function to be called when the form is submitted. The function that gets called first grabs the value from the search input field, then builds a URL to run the search tool. It performs an Ajax call via getJSON() and invokes the 'process' function when the results come back. I already had the process function from the existing implementation.

Post a Comment

Note: Only a member of this blog may post a comment.