File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript - to get the key pressed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript - to get the key pressed" Watch "JavaScript - to get the key pressed" New topic

JavaScript - to get the key pressed

Manikandan G

Joined: Sep 14, 2002
Posts: 4
Is it possible to find which key the user pressed in a textarea using JavaScript.

Hartmut Ludwig
Ranch Hand

Joined: Aug 31, 2002
Posts: 51
Yes it is, but this has nothing to do with Java. JavaScript is a scripting language executed in Browsers. It has some syntax similarities in common with the programming language Java but not much more.
Anyway you will find the solution for your prob
Another good link on javascript is here and a FAQ (also containing the solution for your issue) here
Hartmut Ludwig
Ranch Hand

Joined: Aug 31, 2002
Posts: 51
BTW: there is a JavaScript Forum here on the ranch as well.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Moving to the Java cript Forum. Damn Doe n't type. hit.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4351

Manikandan G,
I hate to say this but, your name does not comply with the Javaranch naming guidelines which can be found at
please register again with a valid name.

Visit my download page
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
well what you need to do is have a variable that detects if the text is being inputted into the text area. I would do something like this
onfocus="SetIt(1)" onblur="SetIt(0)"
the function would be
var InFocus=false;
function SetIt(X){
else InFocus=false;

now for the key catching, you need to use a script like this link has
The only thing you need to do is add the check to the code, which is just an if statement

if you need more help, just say so
I agree. Here's the link:
subject: JavaScript - to get the key pressed
jQuery in Action, 3rd edition