Reputation: 2430
I am trying to make custom autocomplete input (I know about jQuery UI autocomplete, but I decided to write a simple one). Everything went fine, I did all the 'general' stuff - sending data to some PHP script, receiving suggestions. Then I enabled choosing an element on a mouse click, and also did some navigation using down arrow, up arrow and enter keys. But I got stuck with an ambition to enable 'holding down\up arrow key' navigation (flicking through). A handler on my input listens for keyup
event, and I perfectly understand that all I want is keypress
event, because it maintains key hold. But keypress
only works for printable characters which doesn't include down arrow\up arrow. So the question is: how can I make it work without keypress
, or can I somehow override this event's maintained keys?
Thanks everybody, I've found the solution. Although keypress
is meant to be fired only on printable characters, latest Opera and Firefox 5 do support it. But Chrome (and probably Safari, as they are quite similar) doesn't, whereas keydown
gives the result I need.
Upvotes: 0
Views: 544
Reputation: 28817
If you for some reason got stuck in your development, I would recommend Better Autocomplete, which is a lightweight jQuery plugin which is easy to customize.
Upvotes: 0
Reputation: 6334
If there is no way to overcome the keypress
difficulty try something like this. This is pseudocode I didn't do all the keycode detection.
var keyStop
onkeydown = function(){
keyStop = setInterval(function(){scrollDown()},250);
}
onkeyup = function(){
clearInterval(keyStop);
}
Upvotes: 2