|
|
The
onkeypress event attribute in HTML triggers a script when a user presses a key on the keyboard. This attribute is typically used within HTML elements that can receive keyboard input, such as <input> fields or <textarea> elements. |
<input type="text" onkeypress="displayResult()">
The 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
<element onkeypress="script">
| Value | Description |
|---|---|
| script | The script to be run on onkeypress |
| Supported HTML tags: | All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
|---|
A function is triggered when the user is pressing a key in the input field.
<!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 event attributes |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Keyboard Events Attribute |
Uploaded by: | Admin |
Read Articlehttps://develop.horje.com/learn/1434/reference