I need to capture an Enter Key press at any time anywhere on a logon page. It will initiate a logon attempt.
Using jQuery, how would I accomplish this? And would I link it to the body tag?
To check whether user pressed ENTER key on webpage or on any input element, you can bind keypress or keydown event to that element or document object itself. Then in bind() function check the keycode of pressed key whether it's value is 13 is not.
To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.
To check if an “enter” key is pressed inside a textbox, just bind the keypress() to the textbox. $('#textbox'). keypress(function(event){ var keycode = (event.
$(document).keypress(function(e) { if(e.which == 13) { // enter pressed } });
The keydown event is fired when a key is pressed down.
The keypress event is fired when a key is pressed down and that key normally produces a character value.
$(document).keydown( function(event) { if (event.which === 13) { // login code here } });
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