Detecting key press for input text and Detecting Enter key
The order of events related to the keyup event:
1. keydown – The key is on its way down
2. keypress – The key is pressed down
3. keyup – The key is released
The keyup event occurs when a keyboard key is released. The keyup() method triggers the keyup event, or attaches a function to run when a keyup event occurs.
Syntax:-
$(selector).keyup(function);
where, function is optional. It specifies the function to run when the keyup event is triggered. You can attach an event handler to determining key. Below code checks for keyup event for an input text box and then checks if Enter key is pressed.
jQuery( "#inputtextid" ).keyup(function( event ) { var code = (event.keyCode ? event.keyCode : event.which); `if(code == 13) { //Enter key is pressed. Do something } });