382 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
  • United States
blabus says

Alright, for all you JavaScript experts out there, I’ve got an interesting problem I need to solve.

I have a search field on my web application, and that search field is used to search an external datasource through an API . I pass my query (the textbox value) and get back the XML results. Simple.

However, wanting to add that extra bit of sexiness :D , I want to have the results returned in realtime, as the user is typing (as opposed to having to type the whole search query, and then press a ‘Search’ button).

Now, I realize that I can hook into the keyDown/keyUp events of the textbox, BUT that introduces a new problem. The external API I ’m referencing doesn’t allow you to make more than one call per second (obviously to reduce server load, which I understand).

SO basically, I was wondering if anybody knows of a way to detect when the user has FINISHED entering their search term. Basically, what I want to do is detect a specified pause in text entry. So for example, after no text has been added/changed in the textbox for at least 3 seconds, we’ll assume the user has typed what they want to type, and then proceed to process that text (in this case, send it to the API for our results).

Anybody have any ideas? :)

426 posts
  • Beta Tester
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 5 000 and 10 000 dollars
  • United States
vasilios says

I think I know what you can try, but give me like ~10-15 minutes to finish this essay, and then I’ll try and see if what I was thinking would work. :)

(OT: Just noticed we have the same badges. :P)

426 posts
  • Beta Tester
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 5 000 and 10 000 dollars
  • United States
vasilios says

This seems to work (probably not the most practical). Try it out and see if that works. :)

http://pastie.org/647787

382 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
  • United States
blabus says

Awesome, thanks for the help! I’ll try it tomorrow to make sure it works, but it looks like it will (quite ingenious as a matter of fact :) )

by
by
by
by
by
by