Instant Search in pure Javascript (almost instantly)

June 17, 2009

Here’s a really simple method for creating an instant search for a list of items. It lets you quickly filter a long list or table down to the few items you’re looking for.

First here’s a demo.

What’s nice is this only takes a few lines of code (and the magic of jQuery.)


$().ready(function(){
  // Instant Search
  $('#q').keyup(function(){
    $('.search_item').each(function(){
      var re = new RegExp($('#q').val(), 'i')
      if($(this).children('.search_text')[0].innerHTML.match(re)){
        $(this).show();
      }else{
        $(this).hide();
      };
    });
  });
});

Resizing Textareas as You Type with Prototype

May 27, 2009

In my last post I described how you can use jQuery to easily add dynamically scaling textareas to your site. Now here’s one for everyone using Rail’s standard javascript framework Prototype:

Resizing Textareas as You Type with jQuery

May 26, 2009

Here’s some code I’m going to use on every project from now on. It makes all the textarea fields in your forms resize dynamically as the user types. Drop it unobtrusively into any page (running jQuery) and all your textareas expand to fit the text the user has entered.