Listen for keydown
and use e.preventDefault()
to prevent the default behaviour.
The default behaviour for pressing tab
is executed before the keyup
event is being fired. That's why you have to use keydown
instead.
$('input[name="txt1"]').keydown(function(e){
if((e.keyWhich || e.keyCode) == 9){
e.preventDefault();
$('input[name="txt3"]').focus();
}
});
See this Fiddle