jQuery: How to capture the TAB keypress within a Textbox

Viewed 203622

I want to capture the TAB keypress, cancel the default action and call my own javascript function.

9 Answers

You can capture an event tab using this JQuery API.

$( "#yourInputTextId" ).keydown(function(evt) {
   if(evt.key === "Tab")
      //call your function
});

This worked for me:

$("[id*=txtName]").on('keydown', function(e) { var keyCode = e.keyCode || e.which; if (keyCode == 9) { e.preventDefault(); alert('Tab Pressed'); } });

Related