Javascript DOM onkeydown Event

Introduction

Execute a JavaScript when a user is pressing a key:

A function is triggered when the user is pressing a key in the input field.

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="text" onkeydown="myFunction()">

<p id="demo"></p>
<script>
function myFunction() {/* w ww . j av  a 2 s .  c  o  m*/
  document.getElementById("demo").innerHTML = "You pressed a key inside the input field";
}
</script>

</body>
</html>

The onkeydown event occurs when the user is pressing a key on the keyboard.

Bubbles:
Cancelable:
Event type:
Supported HTML tags:












Yes
Yes
KeyboardEvent
All HTML elements,
EXCEPT:
<base>,
<bdo>,
<br>,
<head>,
<html>,
<iframe>,
<meta>,
<param>,
<script>,
<style>, and
<title>



PreviousNext

Related