Easy Tutorial
❮ Met Win Alert Prop Img Lowsrc ❯

onkeypress Event

Event Object

Example

Execute JavaScript code when a user presses a keyboard button:


Definition and Usage

The onkeypress event occurs when a keyboard key is pressed and released.

Tip: The sequence of event execution associated with the onkeypress event:

Note: The onkeypress event can only listen for letters and numbers in all browsers, and cannot listen for some special keys (ALT, CTRL, SHIFT, ESC, arrows, etc.). To listen for a user pressing a key, use the onkeydown event, which is supported by all browsers.

Syntax

In HTML:

In JavaScript:

Parameter Description
SomeJavaScriptCode Required. The JavaScript to be executed when the event occurs.

Browser Support

All major browsers support the onkeypress event.


HTML Tags That Support the onkeypress Event:

The onkeypress attribute can be used with all HTML elements except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>.

❮ Met Win Alert Prop Img Lowsrc ❯