JavaScript
Article

jQuery live count of input characters

By Sam Deering

Some jQuery snippets to capture the input of characters into an input field.

//live input filter
$('#live-search-filter').live('input', function(e)
{
    console.log($(this).val().length);
});

Taking it a step further we can trigger on a count specific number of characters entered.

//live input filter
$('#live-search-filter').live('input', function(e)
{
    var _thisVal = $(this).val();
    //trigger event on 3 or more characters
    if(_thisVal.length >= 3)
    {
        console.log('searching for '+_thisVal);
    }
});

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.