w3resource logo


JavaScript Textarea Object - onkeypress Event handler

JavaScript Textarea Object : onkeypress Event handler

rating JavaScript Textarea Object : onkeypress Event handler has average rating 3 out of 10. Total 2 users rated.

<<PreviousNext>>

Description

The onkeypress event handler of textarea object is defined in an <textarea> and </textarea> (i.e. <textarea name="mytextarea" onkeypress = "JavascriptCode"> </textarea>). It executes some JavaScript code or function when a key is pressed and released over the textarea object.

Version

Implemented in JavaScript 1.2

Syntax

onkeypress = "JavascriptCode"      

Parameter

JavascriptCode : JavaScript statement or JavaScript function.

Example of Textarea object : onkeypress event handler

In the following web document onkeypress event handler shows the effect when a key is pressed and released over the textarea object.

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript Textarea object's Event handler : onkeypress Example</title>
<script type="text/javascript">
ctr=1;
function textareakeypress()
{
document.form1.messg.value = ctr++;
}
</script>
</head>
<body>
<h1 style="color: red">JavaScript Textarea object's Event handlers : onkeypress </h1>
<h3>Goto the text area by pressing tab key or mouse clicking and onkeypress  event will work and count
number of key is pressed and released in the following text box.</h3>
<hr />
<p>Input your details : </p>
<form name="form1" action="#">
<textarea name="TextArea" rows="5" cols="50" onkeypress='textareakeypress()'>
</textarea>
<br />
<p>Number of characters input : </p>
<input type="text" name="messg" size="50" />
</form>
</body>
</html>

View the example of textarea object's onkeypress event handler in the browser

Supported Browser

Internet Explorer 7 Firefox 3.6 Google Chrome 7 Safari 5.0.1 Opera 10
Yes Yes Yes Yes Yes

See also :

Javascript event handlers.

Javascript object's event handlers.



<<PreviousNext>>