views:

305

answers:

3

I am building a autocomplete feature for input text field. Currently I could use mouse click to choose the selection, I'd like to add keyboard control to allow autocomplete control. I monitored the keycode in onkeyup event, it appears for up/down key, the key codes are both 0.

I am wondering whether there is any better way to do so.

Thanks.

+1  A: 

Look at the example at http://www.w3schools.com/jsref/jsref_onkeydown.asp. It works for me in both FF3.5 and IE8.

Geerad
+1  A: 

Keycodes 37 - 40 should do it for you. They map as 37=left, 38=up, 39=right, 40=down.

anschauung
+1  A: 

There's usually not a justifiable reason to re-invent the wheel. That said, I would recommend using jQuery with the AutoComplete plugin.

Josh Stodola