-5

I am using an android phone and when I press any key in my textarea, it looks like that e.keycode does not function properly (It does not return true the keycode value for each key). But it always triggers when I press any key in my textarea.

function d(e) {
  var key = (e.keyCode);
  if (key == 229) {
    alert("hello");
    return false;
  }
}
<textarea id="msg" onkeyup="d(event)"> 
</textarea>

NOTE: For testing purposes, use your mobile phone (specifically android phone) to be able to reproduce the problem.

MMJM
  • 117
  • 1
  • 11
  • 2
    https://stackoverflow.com/questions/4471582/javascript-keycode-vs-which – tom10271 Jul 16 '17 at 08:22
  • 1
    @EvgenyKolyakov: No. It would be `e.which`, but given the OP's quoted symptom, it's not that they're using the wrong property (but it's unclear what *is* wrong). – T.J. Crowder Jul 16 '17 at 08:23
  • You forgot } at the end – Djordje Vujicic Jul 16 '17 at 08:23
  • *"But it always triggers when I press any key in my textarea."* There's nothing obvious in the quoted code that would cause that. Please update your question with a **runnable** [mcve] using Stack Snippets (the `[<>]` toolbar button) demonstrating the problem. (I've added the snippet for you, but it doesn't do what you describe.) – T.J. Crowder Jul 16 '17 at 08:23
  • @aokaddaoc still the same the problem exist – MMJM Jul 16 '17 at 08:24
  • Well you can solve it by `console.log(e)` – tom10271 Jul 16 '17 at 08:25
  • You've clearly been back since the comments above. Why don't you address them, and make it possible to answer your question? – T.J. Crowder Jul 16 '17 at 08:57

2 Answers2

1

219 is the keyCode which need to be used

function d(e) {
  var key = (e.keyCode);

  if (key == 219) {
    alert("hello");
    return false;
  }
}
<textarea id="msg" onkeyup="d(event)"> 
 </textarea>
brk
  • 48,835
  • 10
  • 56
  • 78
-1

The keycode for { is 219. Some browser uses keycode, some uses which. There is also charCode.

function d(e){
    var key = e.which || e.keyCode || e.charCode || 0;
    if (key == 219){
         alert("hello");
         return false;
    }
}
<textarea id="msg" onkeyup="d(event)"> 
</textarea>
Hassan Imam
  • 21,956
  • 5
  • 41
  • 51