Disclaimer: I am anything but a Javascript expert, so I'm not even sure if I'm approaching this correctly...
I want to be able to trigger an event in Javascript, but be able to cancel that event if another event occurs. So, what I'm looking to accomplish is:
- User begins typing in a text box.
- When textbox contents change, trigger an event that makes an AJAX call
- BUT, if the user keeps on typing, cancel that event, because I don't want to do the query until after they are finished typing
i.e. If the user is typing "foobar" in, I don't want to do the AJAX search until they're done typing. There is no reason for me to do:
AJAX("f") and then AJAX("fo") and then AJAX("foo") and then AJAX("foob") ...
when I could have just done a single call when they were done typing AJAX("foobar")
... am I making any sense? Or is there a better way to approach this?
Oh, and then the kicker: I'd like to avoid JQuery/Prototype, and do this with just straight javascript... yeck!