I try to trigger a button when in an input field the return key has been hit. This works. But if I hit the tab key nothing is triggered because the TAB key event isn't captured.
Here is my JQ code snippet for example:
$("input[name=input]").on("keypress, keydown, keyup", function(e) {
var code = e.keyCode || e.which;
if ( code == 13 || code == 9 ) {
$("input[name=btn]").trigger("click");
}
});
I can't figure out how to get the tab key stroke working like a return key stroke.
e.preventDefault()
andreturn false
. Why?` – Mcgehee