On 27 Feb 2007, at 12:38:19, Nick Roper wrote:

Hi,

A customer has requested that they should be able to navigate between input fields on a form by using the Enter key - i.e. to replicate the action of the Tab key.

I've seen examples of Javascript code to do this, but I'd be interested in any feedback on whether there are any issues with this and what the best approach is to implement.


I would say that the main issue is that the Enter key is used to submit a form. When I fill in a form, I usually Tab from field to field and, when at the end, hit Enter to submit it. There's no way I would be pleased to find the expected behaviour was broken. The implication is that I would be expected to actually move my hands away from the keyboard to use the mouse to submit the form, which is downright annoying.

On the other hand, if this is an intranet or extranet app with a limited user base, you might be able to get away with it. But as a general rule, changing the standard behaviour of the browser is an appallingly bad idea.

If they insist on doing it that way, the best approach is probable to attach an "onkeypress" handler to the form in the onload event, or some suitable ondomcontentloaded event if the page is heavy with graphics. The event handler should be able to work out which element had the focus when the enter key was pressed, and work out which field to move focus to. Then it has to cancel the default action (i.e. submitting the form) - this works differently cross-browser, so check out existing libraries for "preventDefault" to make sure you cover all the cases.

By the way, what happens if one hits Enter when the focus is on a checkbox or radio button? In particular, with a set of radio buttons, would it move focus to the next button in the group, or would it move to the next control that wasn't a member of the group?

Regards,

Nick.
--
Nick Fitzsimons
http://www.nickfitz.co.uk/





*******************************************************************
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
*******************************************************************

Reply via email to