Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery live search

Tags:

jquery

How i can i check the value of an input field continuously after it has been focused once ? (with jquery).I'm looking to make a live search and completely remove the submit button on my form.

like image 885
andrei Avatar asked Dec 22 '22 19:12

andrei


1 Answers

I would bind the keyup and mouseup events to the input

$("#search").keyup(Search).mouseup(Search);

function Search(event)
{
    // keyup for keyboard entry
    // mouseup for copy-pasting with the mouse        
}

After fighting with this in jsfiddle I finally came up with this:

$("#search").keyup(function(e) {
    Search(e);
}).bind("paste", function(e) {
    // have to do this so the DOM can catch up on mouse right-click paste
    setTimeout(function() { Search(e); }, 100);
});

I wasn't aware of the paste event, but clearly, it is awesome

Working example: http://jsfiddle.net/rLAxL/1/

like image 76
hunter Avatar answered Jan 05 '23 12:01

hunter