Listen to key down event for input text element in JavaScript

Description

The following code shows how to listen to key down event for input text element.

Example


<HTML>
<BODY>
  <SCRIPT>
    function checkKey(e) {<!--   w w  w . j  a  v  a  2s.  c o  m-->
      document.writeln("You entered the character "
          + String.fromCharCode(e.keyCode) + ".");

    }
  </SCRIPT>

  <FORM name="theForm">
    <INPUT type=text name="theText" onKeyDown="checkKey(event);">

  </FORM>

</BODY>
</HTML>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window