Horje

How to Execute a JavaScript when a user presses a key

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" onkeypress="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 presses a key



Single Articles
Example of HTML onkeypress Event AttributeKeyboard Events Attribute
Definition and Usage HTML onkeypress Event AttributeKeyboard Events Attribute
Browser Support of HTML onkeypress Event AttributeKeyboard Events Attribute
Syntax of HTML onkeypress Event AttributeKeyboard Events Attribute
Attribute Values of HTML onkeypress Event AttributeKeyboard Events Attribute
Technical Details of HTML onkeypress Event AttributeKeyboard Events Attribute
How to Execute a JavaScript when a user presses a keyKeyboard Events Attribute


Related Articles
List of Keyboard Events Attribute Keyboard Events Attribute
What is HTML onkeydown Event Attribute Keyboard Events Attribute
What is HTML onkeypress Event Attribute Keyboard Events Attribute
What is HTML onkeyup Event Attribute Keyboard Events Attribute

Type:
Html
Category:
Web Tutorial
Sub Category:
Keyboard Events Attribute
Uploaded by:
Admin