![]() |
Definition and UsageThe onkeypress attribute fires when the user presses a key (on the keyboard). Tip: The order of events related to the onkeypress event:
Note: The onkeypress event is not fired for all keys (e.g. ALT, CTRL, SHIFT, ESC) in all browsers. To detect only whether the user has pressed a key, use onkeydown instead, because it works for all keys. Applies toThe onkeypress attribute is part of the Event Attributes, and can be used on any HTML elements.
Browser Support |
A function is triggered when the user is pressing a key in the input field.
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" onkeypress="myFunction()">
<script>
function myFunction() {
alert("You pressed a key inside the input field");
}
</script>
</body>
</html>
html onkeypress attribute |
How to Execute a JavaScript when a user presses a key | HTML Attribute |
Read Full: | HTML Attribute |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Attribute |
Uploaded: | 3 weeks ago |
Uploaded by: | Admin |
Views: | 968 |
Reffered: https://www.w3schools.com/tags/att_onkeypress.asp