views:

254

answers:

2

I currently have a table which only has a single editable column. I have a jQCuery change() event associated with the column's input controls to prevent any non numeric keys being pressed, other than tab / delete / backspace.

I would like to replace the Enter key with a Tab press.

Can someone please show me the relevant statement to replace the keyCode based on the Enter character being intercepted?

+2  A: 

You can't replace it, but you can handle it, like this:

$(".myField").keyup(function(e) {
  if(e.keyCode == 13) {
    $(this).closest("tr").next("tr").find("input").focus();
    return false; 
  }
});

Just modify the $(this).closest("tr").next("tr").find("input").focus(); (currently going to the next row) portion to whatever your layout is, to find the next element you want to move to and focus it.

Nick Craver
+1 - Nick, you're a SO troll... you seriously are all over this site
hunter
@Hunter - Working on jQuery 1000 badge, then I'll pick another category :) Bugfixing at work leaves 5 minutes here and there to answer questions.
Nick Craver
Sure, I just thought that if there was a way to emulate the other keypress I could handle it in my existing code without the expense of another dom lookup.
Brian Scott
A: 

Since you are capturing the key's anyway, why not just move focus when the enter key is used rather than try to change keystrokes.

Dustin Laine