Question

So far i have this being called on keypress.

function chkenter()
{
  e = event.keyCode;

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

but even though i set the keycode to 9 it doesn't tab over to the next control. How can i accomplish this? I'm working in Asp Classic.

What I ultimately want is for the focus to move to the next element. The next element's id, however, is not determined completely because its id was set in a loop, but at this point it exists. How can i set focus to the next control is the question.

Was it helpful?

Solution

It is an IE only script, so if you try to run it on firefox it wont work.

For it to work on IE, remove "return false;" from your code and dont forget to atach this function into "onkeydown" event.

OTHER TIPS

You can do this using jQuery like so:

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top