HTML onkeydown Event Attribute

Description

The event attribute onkeydown allows you to set the script to fire when the user presses any key.

Syntax

<element onkeydown="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html>
  <html>
    <head>
      <title>Event Attribute onkeydown</title>
    </head>
  <body>
    <p>Click any button in the form to run the script:</p>
    <input type="text" onkeydown="keyboardTest()">
<script>
function keyboardTest() {
  alert("You see this window because you triggered the script"); 
}
</script>
  </body>
</html>

Supported Tags

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

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
XYesYesYesXX
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYesYesXXX