Horje
HTML onkeydown Attribute

Definition and Usage

The onkeydown attribute fires when the user is pressing a key (on the keyboard).

Tip: The order of events related to the onkeydown event:

  1. onkeydown
  2. onkeypress
  3. onkeyup

Applies to

The onkeydown attribute is part of the Event Attributes, and can be used on any HTML elements.

Elements Event
All HTML elements onkeydown

Browser Support


How to Execute a JavaScript when a user is pressing a key - HTML onkeydown

Input Example. A function is triggered when the user is pressing a key in the input field.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<p>A function is triggered when the user is pressing a key in the input field.</p>

<input type="text" onkeydown="myFunction()">

<script>
function myFunction() {
  alert("You pressed a key inside the input field");
}
</script>

</body>
</html>

Output should be:

How to Execute a JavaScript when a user is pressing a key - HTML onkeydown




html onkeydown attribute

Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference