I have a case where I want to capture the simultaneous key press event of "shift+tab" key using jquery. Actually as you all know it is used to move tab in backward direction but for me in one scenario tha tab was not working in any direction i.e. neither forward nor backward. so I found a jquery function for moving tab in forward direction as follows:-
$(':input').live('keydown', function(e) { var keyCode = e.keyCode || e.which; if (keyCode == 9) { tindex = parseInt($(this).attr("tabindex")) + 1; if($(":input[tabindex='" + tindex + "']")) { $(":input[tabindex='" + tindex + "']").focus(); } } });
Now I want to move tah tab in backward direction as well. Can somebody guide me how can i achieve this???
To detect shift+tab press with JavaScript, we can check if the shiftKey is true and the keyCode is 9. to check if the shiftKey is pressed and while tab is pressed. The keyCode for the tab key is 9. event is the keyboard event object we get from the keyboard event handler callback's parameter.
Your question asks for they keycode for shift+tab, but you want to detect the up key? Peter, the keyCode 16 is for the Shift key.
You can use e.shiftKey
to check whether the shift key was held when the event was triggered.
If you add an if
statement to your event handler, checking whether the shift key was held, you can perform different actions:
if(keyCode == 9) { if(e.shiftKey) { //Focus previous input } else { //Focus next input } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With