0

Can anyone help with a JavaScript key event.

I am looking to emulate a "Tab" operation in part of a document (table) where the enter key acts the same as a tab button press.

I have been looking in to how to capture keypresses but find little to no information on how to capture a specific key press and then convert that action in to another type of key event like a tab key press.

When the focus is not on the table, I am looking at normal key operation.

Has anyone got any ideas on how the achieve this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mark Giblin
  • 1,086
  • 2
  • 13
  • 20
  • What's your (representative/minimal/[SSCCE](http://sscce.org/)) HTML on which you want to act? What do you want to happen when the user presses 'enter'? – David Thomas Nov 01 '13 at 23:04
  • You can't. The DOM API has a notion of ["trusted events"](http://www.w3.org/TR/DOM-Level-3-Events/#trusted-events), you can simulate a key press but you can't automatically invoke the default action as if the user did it. Let me quote the spec: "Most untrusted events should not trigger default actions, with the exception of click or DOMActivate events." – Benjamin Gruenbaum Nov 01 '13 at 23:04
  • possible duplicate http://stackoverflow.com/questions/1601593/fire-tab-keypress-event-in-javascript – Yaron U. Nov 01 '13 at 23:05
  • On pressing Enter the action is to have that event replace with a Tab event. The being only in a elsewhere in the document.body the normal action of enter is to work as expected.
    – Mark Giblin Nov 01 '13 at 23:15
  • The reason for this need is to have the enter key tab across to the next – Mark Giblin Nov 01 '13 at 23:17
  • @MarkGiblin In that case, I'd recommend capturing the enter keypress and running JavaScript to move focus to the next input. – AlliterativeAlice Nov 01 '13 at 23:21
  • I thought about that but how would you find the next input field when you have a grid of them 6 wide by 7 deep and no tab indexes set? Thats the other half of the equation, using javascript to se the tab indexes on a table of input fields – Mark Giblin Nov 02 '13 at 00:22

0 Answers0