Skip to content
Advertisement

Enter key pressed fast

I am searching from around 5000 records. The search button is working fine. But when I press enter key too fast. It does not bring the result back. I tried codes from stckoverflow.com already but it’s not working for me.

My textbox for search is

JavaScript

Javascript for searchfilter()

JavaScript

HTML

JavaScript

Advertisement

Answer

Demo http://jsfiddle.net/togr18Lb/1/

Ok, here’s your solution.

Abort any previous requests when a new one is made so as not to flood the server with them.

Slow down the requests by waiting until the user stops typing.

The button works, so all we need to do is bind keyup and change of input field to trigger that button, rather than duplicate code. And we do this with jQuery, not using onkeyup="".

To make sure we’re not making unnecessary requests returning false when the enter key is pressed is correct, however we use .preventDefault() instead.

JavaScript

jQuery

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement