Quick References
      ADO
      ASP
      CSS2
      HTML
      JavaScript
      Jet SQL
      VBScript
      WML
      WMLScript
      WSH
      XHTML
      XML DOM
      XSLT

Features
      Knowledge Base
      Tutorials

Partners
     ZVON.ORG
     XML
     Planet Source Code
     VisualBuilder
     Web Design
     Your HTML Source
     XML/XSLT Forums
     ASPAlliance
     Scripts
     
     Programmers Heaven
     Tek-Tips Forums
     Developer Fusion
     Code Project









EVENT:  onkeypress

onkeypress="action"
 
The onkeypress event is associated with press of a key on the keyboard while the mouse is inside a selected HTML element. In other words, the key press event occurred while the HTML element was in focus. Whenever you press the key, the script code of the onkeypress is executed. This script can also call functions or subroutines which contain code that you want to run when this event occurs. For example, if you only want numbers to be entered, you could capture the value of the key and take appropriate action if a non-numeric key was pressed.
 
The similar onkeydown event is associated with the pressing down of a key, and the onkeyup event is associated with the release up of a key.
 
In this example, place the mouse inside the textarea element and type in a word. Every time you press a key, one line of JavaScript code is executed which causes an alert box to be displayed with a message. Note that the character does not appear in the textarea until after you have clicked okay in the alert.
 
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>DevGuru XHTML onkeypress Tag Example</title>
</head>
<body>
<textarea onkeypress="javascript: alert('A key was pressed')">
</textarea>
</body>
</html>

 
Output:


 


Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information