Hello There, I' new to JS ,could someone help me or explain ,how the "keydown" event works ? when the event is triggered with numeric keys , the value is being


( for ex: if I press key-3 ,the input shd become empty ,but i can see value 3 in input area )

you will need to share your code if you need help with debugging.

You can read about the keydown event here:

https://codepen.io/Raviteja-Yellam/pen/vEBOmdz , Thanks for your response ,Please check it here .

Not sure, it might have to do with how the keydown event must be dispatched before the beforeinput and input events.

3.7.5.1. keydown
This event type MUST be dispatched before the beforeinput, input, and keyup events associated with the same key.

If you add another event listener for input you can clear the input elements using that event. Use e.currentTarget.value instead of using an index.


  • Why does it have to be a keydown event?

  • How are the values to be used? Surely they must exist somewhere, otherwise how are you going to validate?

  • If you clear the input, how is the user supposed to know if they typed the correct numbers? If you just want to hide the input, you could use the type="password" type and do some input/pattern validation to only allow numbers and backspace.

1 Like