HTML Event attribute: onkeydown
[this page | pdf | back links]
The HTML onkeydown attribute specifies the event
that is triggered when the user is pressing a key. It applies to all visible elements.
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
onkeydown, onkeypress, onkeyup: try pressing a key in this input field
<input type="text" onkeydown="myOnkeydown()" onkeypress="myOnkeypress()" onkeyup="myOnkeyup()">
<br><br><b id="keypress1"></b> <b id="keypress2"></b> <b id="keypress3"></b><br>
<script>
function myOnkeydown() {
document.getElementById("keypress1").innerHTML = "Key down";
}
function myOnkeypress() {
document.getElementById("keypress2").innerHTML = "Key being pressed";
}
function myOnkeyup() {
document.getElementById("keypress3").innerHTML = "Key up";
}
</script>
</body>
</html>
|
NAVIGATION LINKS
Contents | Prev | Next | HTML Attributes