I'm trying to implement a search box using php and jquery (the seach results are coming from a database). What I want to do is that as the user type into the search box, a query is made to find the data that contains the keyword the user entered into the search box. The problem I'm having is that I have something like this:
$("#my_search_box").keyup(function(){
retrieve_results($(this).val());
});
The problem with doing this is that, the function retrieve_results() is called every time the user is done typing (of course, cause that's what the keyup is there for). Therefore, this can get very slow because if the user type a word that has like 10 characters, the retrieve_results() function gets called 10 times in a row. Also, I should mention that inside my retrieve_results() function, I'm doing an Ajax request using jQuery $.ajax to get the results. So my question is the following:
How do I make it so that my function retrieve_results() doesn't get executed everytime the user stops typing (every time the key is up). I want to keep that functionality though, I don't want the user to click on a "Search" button or something. I just would like my retrieve_results() function to get called only once when the user is done entering all the keywords (not everytime the user enters a letter or something)
Thank you