aspose file tools*
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
Author

JavaScript - to get the key pressed

Manikandan G
Greenhorn

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


Man(i)
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
here.
Another good link on javascript is here and a FAQ (also containing the solution for your issue) here
sl
Hartmut
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: 4339
    
    2

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


SCJP
Visit my download page
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
<script>
var InFocus=false;
function SetIt(X){
if(X==1)InFocus=true;
else InFocus=false;
}
</script>

now for the key catching, you need to use a script like this link has
http://www10.brinkster.com/A1ien51/Scripts/KeyCode.htm
The only thing you need to do is add the check to the code, which is just an if statement
if(InFocus){
//TheCode
}

if you need more help, just say so
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaScript - to get the key pressed
 
Similar Threads
Enter key
How to identify when refresh button of browser or f5 is pressed
onblur and event at the same time !
extremely urgent, help needed
How to trap the Keyboard(key) value