Link to home
Start Free TrialLog in
Avatar of Jeffrey Dake
Jeffrey DakeFlag for United States of America

asked on

Detecting tab press in javascript

I would like to have a text-area or a text input, that when the user presses tab (ie. Trys to go to the next form field), I can fire some JavaScript that opens up a hidden element.  Does anyone know a good way to do this?  Do I need to listening for any key-press on the page, or is there a way to do it specifically when they are only within the text-area.

Thanks in advance for the help.
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

Ttry something like:

   $(document).delegate('.textAreaClass', 'keydown', function(event)
   {
      var keyCode = (event.keyCode ? event.keyCode : event.which);
      if (keyCode == '9')
      {
         event.preventDefault();
         alert('TAB');
      }
   });

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jeffrey Dake

ASKER

Thanks guys.
please note : https://api.jquery.com/event.which/

The event.which property normalizes event.keyCode and event.charCode. It is recommended to watch event.which for keyboard key input.
Thanks leakim971