Catching Tab keystroke

Hi,

I was wondering if there is any way to catch a tab keystroke so that I can perform an action only when someone tabs out of an input field on a webpage.
It's only tab that I want to perform this action and not when you leave the field by other means (using the mouse, enter, etc).

Is this possible?

Cheers

Comments

  • Sorry been an idiot. I just worked out that I need to use onKeyDown instead of onKeyPressed and then check for event.keyCode = 9.

    Sorry about that.

    While I'm here though, what would be the best way to do this so that it works for all the browsers, I'm trying it on IE at the moment but I think Netscape requires something slightly different when using some of the events.

    : Hi,
    :
    : I was wondering if there is any way to catch a tab keystroke so that I can perform an action only when someone tabs out of an input field on a webpage.
    : It's only tab that I want to perform this action and not when you leave the field by other means (using the mouse, enter, etc).
    :
    : Is this possible?
    :
    : Cheers
    :

  • Hi,

    Yes, NN has different ways... especially with non-character keycodes...
    I tested this on NN6 and the event only fired once then I had to reload the page... is there a workaround for this, anyone?



    function keyDown(ev)
    {
    var key = ev.which;
    alert("Key code: " + key);
    }
    document.onkeydown = keyDown;


    This is the IE version, and works for all non-character codes as well...



    function keyDown()
    {
    var key = window.event.keyCode;
    alert("Key code: " + key);
    }









    To make it work on all browsers first detect the userAgent then call the relevant function... Still, I think you'll likely to have problems with NN...

    : Sorry been an idiot. I just worked out that I need to use onKeyDown instead of onKeyPressed and then check for event.keyCode = 9.
    :
    : Sorry about that.
    :
    : While I'm here though, what would be the best way to do this so that it works for all the browsers, I'm trying it on IE at the moment but I think Netscape requires something slightly different when using some of the events.
    :
    : : Hi,
    : :
    : : I was wondering if there is any way to catch a tab keystroke so that I can perform an action only when someone tabs out of an input field on a webpage.
    : : It's only tab that I want to perform this action and not when you leave the field by other means (using the mouse, enter, etc).
    : :
    : : Is this possible?
    : :
    : : Cheers
    : :
    :
    :

    [hr][grey]To err is human, but to really foul things up requires a computer. (Farmers Almanac)[/grey] :-)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories