View Full Version : Using onKeyDown with Tab key

07-08-2005, 11:18 PM

When I do the following in my form:

OnKeyDown="javascript: if(event.keyCode == 9){fieldname.focus()}"

It tabs to the wrong spot on the form. Likewise when I change the fieldname to any other field name in the form. What I want is to be able to vertically tab down the page so a user can input their data (The inputs are in 2 columns). The left side is a 'bill to' and the right side is a 'ship to'. I want all the bill to stuff filled out first before going to the second column.

Not exactly sure why this is not working, but any help would be apprecaited. Thanks.

07-09-2005, 12:11 AM
Try defining tabindex attributes for the elements.

07-09-2005, 12:38 AM
Well that did it. Thanks for the advice, didn't realize it was that easy.

On a side note, I think it's lame that the tab key is so gosh darn hard to define with JavaScript. Oh well, thanks!

07-09-2005, 01:32 AM
On that note, controlling the event return value is key.

onkeydown="return event.keyCode == 9 ? fieldname.focus() || false : true"