Facebook
From Diminutive Parakeet, 1 Week ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 53
  1. <html><head> <title>Example: Working with form Events</title>
  2.    <style type="text/css">
  3.       p {
  4.          font-family: Verdana;
  5.          background: #FA8B7C;
  6.          color: #fff;
  7.          padding: 10px;
  8.          border: 4px solid #555;
  9.       }
  10.    </style>
  11. </head>
  12. <body>
  13.    <form>
  14.       <p><label for="name"> Name: <input autofocus id="name" name="name" /></label> </p>
  15.       <p> <label for="nick"> Nickname:<input id="nick" name="nick" /></label>  </p>
  16. <button type="submit">Submit</button>
  17.    </form>
  18. <span id="output"></span>
  19. </body>
  20. <script>
  21.    var items = document.getElementsByTagName("input");
  22.    for (var i = 0; i < items.length; i++) {
  23.      items[i].onkeyup = keyboardEventHandler;
  24.   }
  25. function keyboardEventHandler(e) {
  26.      document.getElementById("output").innerHTML = "Key pressed is: " +
  27.         e.keyCode + " Char:" + String.fromCharCode(e.keyCode);
  28.   }
  29. </script>
  30. </html>