2

I want to trigger the Tab key when I press the down key.

So when I press the down arrow key it should have the same effect if use I the Tab key.

Does anyone know for my issue a jquery or javascript code? :)

drama
  • 19
  • 6

2 Answers2

4

No, you can't trigger a different key based on a keypress, for good reasons. Otherwise, you could trick browsers into auto-completing passwords or other sensitive information or even cause a password manager to do a global autofill.

That said, if all you want to do is, say, make the down key jump from one form field to the next, like the tab key does, that's easy. Just intercept the keypress in question and check whether it is the down key (charCode 40). If it is, execute whatever code you want to use to handle the event.

elixenide
  • 44,308
  • 16
  • 74
  • 100
2

Hi this could possibly fix your problem

arrow keys are only triggered by onkeydown, not onkeypress keycode for Down is 40

function convertDownToTab() {
  if(event.keyCode==40) {
    event.keyCode = 9;
  }
}
document.onkeydown = convertDownToTab;

Or Using jQuery, you can do this When you press the down arrow key (keyCode 40), the next input receives the focus.

$('input, select').keydown(function(e) {
if (e.keyCode==40) {
    $(this).next('input, select').focus();
}
});

Hope this helps

Ryan Gavin
  • 689
  • 1
  • 8
  • 22