Make an input key like a tab key in Javascript

So far, this is due to a keystroke.

function chkenter()
{
  e = event.keyCode;

  if (e == 13)
  {
    event.keyCode = 9;
    return false;
  }
}

but even if I set the key code to 9, it does not go to the next control. How can i do this? I work at Asp Classic.

Ultimately, I want to focus in order to move on to the next element. However, the next identifier of an element is not completely determined, because its identifier has been set in a loop, but at the moment it exists. How to set focus to the next control is a question.

+3
source share
2 answers

IE script, , firefox, .

IE, "return false"; onkeydown.

+1

, jQuery:

function checkKey(e){
    if( e.keyCode == 13 ){ // if enter key
        var e = jQuery.Event('keydown'); // create a manual event
        e.which = e.charCode = 0;
        e.keyCode = 9; // set the new event to "tab"
        $(this.target).trigger(e); // trigger the new event (on the document)
        return false;  // cancels the original "enter" event from executing
    }
}
// lets say you bind the event on the whole document...
$(document).on('keydown', checkKey);
0

Source: https://habr.com/ru/post/1718833/


All Articles