Example
Execute a piece of JavaScript when the user presses a key:
<input type="text" onkeypress="displayResult()">
Browser support
IE
Firefox
Chrome
Safari
Opera
All major browsers support the onkeypress attribute.
Definition and Usage
The onkeypress property is triggered when the user presses a key (on the keyboard).
Tip: The order of events relative to the onkeypress event:
onkeydown onkeypress onkeyup
Note: In any browser, the onkeypress event will not be triggered by all key presses (such as ALT , CTRL, SHIFT, ESC).
Note: The onkeypress attribute is not applicable to the following elements:
, , ,