onkeydownEvent
Example
Execute Javascript code when the user presses a key:
<input type="text" onkeydown="myFunction()">
Try it Yourself »
Definition and Usage
The onkeydown event occurs when the user presses a keyboard key.
Tip:The trigger order of events related to the onkeydown event:
- onkeydown
- onkeypress
- onkeyup
Syntax
In HTML:
<element
onkeydown="SomeJavaScriptCode">
In JavaScript:
object.onkeydown=function(){SomeJavaScriptCode};
| Parameter | Description |
|---|---|
| SomeJavaScriptCode | Required. Specifies the JavaScript to execute when the event occurs. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the onkeydown event
HTML tags supporting this event:
The onkeydown attribute can be used on all HTML elements, except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>.
Event Object Other Extensions