# Solved: html/javascript -- redefine the enter key to act as tab



## andynic (May 25, 2007)

Hi,

How can I redefine the enter key so that it functions as the tab key for all fields in an html form?

The code below globally disables the enter key, but I can't find a way to make it redefine the key press as the tab key rather than disabling the key press.
Thanks for your help/
Andynic


----------



## allnodcoms (Jun 30, 2007)

Why would you want to do this?

Anyway, AFAIK you can't fire your own events as such, so you can't remap the key press. You'd have to attach a key down handler to each field, or an 'onChange' handler (which fires when a user confirms edits to a control) and manually set the focus to the next control in the array. 

You can't set a global handler for the key down as it would stop the user from tabbing to a valid button and hitting return to activate it.

Danny


----------



## andynic (May 25, 2007)

Thanks for the explanation, Danny.
The reason I wanted to do it is that there are many fields in the page and a number of buttons. For some reason when the user hits the Enter key, it activates one of the buttons for some reason (it is the first on the page) and sends the user off to another webpage which is not user-friendly in this data entry application.

I guess what I'll do is to use the code I showed above to disable the Enter key and add an alert telling the user to always use the Tab key instead.
Andynic


----------



## allnodcoms (Jun 30, 2007)

Sounds like it's a submit button... Just make it a straight forward button and submit the forms in the onClick handler, that should solve the enter key issue.

Danny


----------



## andynic (May 25, 2007)

Thanks, Danny. Spot on!
Will change it.
Thanks.
Andynic


----------

