Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript - to get the key pressed

 
Manikandan G
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to find which key the user pressed in a textarea using JavaScript.
 
Hartmut Ludwig
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW: there is a JavaScript Forum here on the ranch as well.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Java cript Forum. Damn Doe n't type. hit.
 
Randall Twede
Ranch Hand
Posts: 4481
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic