I am using this code to handle keydown event for tab
and enter
key for an input.
$(document).on('keydown', ".className" , function(e) {
var keyCode = e.keyCode || e.which;
alert(keyCode) // does not work for 'next'
if (keyCode == 9) { //tab key // does not work for 'next'
e.preventDefault();
if( $(this).parents('tr').next('tr').length == 0){
$('.add_info').click();
}
$(this).parents('tr').next('tr').find('input:first').focus();
}
if (keyCode == 13) { //enter key
e.preventDefault();
$('.anotherField').focus();
}
});
The code for the tab
key does not work on a mobile's browser. The numeric keyboard shows up for the .className
fields as the input type is number
, so it has Next
key along with other keys. I tried alert(keyCode)
just to get the keycode for Next
, but the event does not trigger. Is there anyway I could override the default behavior of the Next
key?