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
All Event Handlers
onKeyDown
onKeyUp
EVENT HANDLER: onKeyPress
onKeyPress
= myJavaScriptCode
Event handler for
Document
,
Image
,
Link
,
TextArea
.
The
onKeyPress
event handler executes the specified JavaScript code or function on the occurance of a KeyPress event. A KeyPress event occurs when the user presses or holds down a key.
The
onKeyPress
event handler uses the following
Event
object properties.
type
- this property indicates the type of event.
target
- this property indicates the object to which the event was originally sent.
layerX
- the cursor location when the KeyPress event occurs.
layerY
- the cursor location when the KeyPress event occurs.
pageX
- the cursor location when the KeyPress event occurs.
pageY
- the cursor location when the KeyPress event occurs.
screenX
- the cursor location when the KeyPress event occurs.
screenY
- the cursor location when the KeyPress event occurs.
which
- this represents the key pressed as its ASCII value.
modifiers
- lists the modifier keys (shift, alt, ctrl, etc.) held down when the KeyPress event occurs.
The following example shows the use of the
onKeyPress
event handler to display a message in the text box.
Code:
<body>
<form action="" method="POST" id="myForm" >
<input type="text" name="myText" onKeyPress="changeVal()">
<script type="text/javascript" language="JavaScript">
s1 = new String(myForm.myText.value)
function changeVal() {
s1 = "You pressed a key"
myForm.myText.value = s1.toUpperCase()
}
</script>
</form>
</body>
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information