0

I am trying to display the key entered value in the console. Right now I'm debugging. It's going inside the keyPress function, but I don't see any logs printed.

console.log("keyPress--->", e);

Can you tell me how to fix it so that in the future I will fix it myself.

I used this link as a reference: How to get input textfield values when enter key is pressed in react js?

I am providing my code snippet and sandbox here. All my code is in tab-demo.js

 handleChangeText(e) {
    debugger;
    console.log("handleChangeText--->", e);
    this.setState({ value: e.target.value });
  }

  keyPress(e) {
    debugger;
    console.log("keyPress--->", e);

    if (e.keyCode == 13) {
      console.log("value", e.target.value);
      // put the login here
    }
AndrewL64
  • 15,794
  • 8
  • 47
  • 79
  • I tried the provieded sandbox and it logs "keyPress---> 0" in the console properly. – Gleb Kostyunin Dec 11 '18 at 21:40
  • @GlebKost hey thanks for your reply.... everytime it prints 0, eventhough if I press new character, can you tell me how to fix it –  Dec 11 '18 at 21:49

1 Answers1

0

You want to console log the input value, not the input itself.

console.log("keyPress--->", e.target.value);

Here's a dummy component called App which logs the input value as you wanted: https://codepen.io/andrewl64/pen/ebNGwr

AndrewL64
  • 15,794
  • 8
  • 47
  • 79
  • hey I updated the code in sandbox but still not working...can you help me in updating sandbox https://codesandbox.io/s/l20n739xqz –  Dec 11 '18 at 21:32
  • Can you please replicate what you have so far here: https://codepen.io/pen?template=ELRjGo – AndrewL64 Dec 11 '18 at 21:35
  • ReactJS is already hooked up so you just need to write your components in. – AndrewL64 Dec 11 '18 at 21:36
  • it would be great if you include in my sandbox since I have already all the components included there...please help codesandbox.io/s/l20n739xqz –  Dec 11 '18 at 21:39
  • I'm not too comfortable with sandbox unfortunately. – AndrewL64 Dec 11 '18 at 21:41
  • hey thanks for your reply..in my sandbox .... everytime it prints 0, eventhough if I press new character, can you tell me how to fix it... –  Dec 11 '18 at 21:50