onkey… what what

Xoliswa Nongcebo Shandu
2 min readJan 25, 2021

--

JavaScript is not my strong point, but I keep learning useful events and I appreciate that. I am quite forgetful when I don’t use something often so I will just use this as my reminder when I need to grab it again. So I hope I do remember this post when I need it.

Today I learnt something that seems simple but was confusing me a bit until I started to read the way they work and test it out and see how it works so that I can eventually make my code work the way I intend.

Input field manipulation, so I needed to find out if there is any text or characters on the input field, javascript says alrighty, you can use either of the following:
1. onkeyup()
2. onkeydown()
3. onkeypress()

So what do these 3 events actually do, so instead of being lazy and seeing which one works for me and moving on, I decided to pay a little more attention so that I can learn more.

onkey… is self explanatory, it means on the keyboard. Input fields work with the keyboard for entering data unless you copy and paste.

  1. onkeyup()- When I click on the keyboard and then release, that is the onkeyup() event. Once the keyboard key is released after being pressed then the event fires.
  2. onkeydown()- If I click on any key on the keyboard, even on special characters e.g cmd, ctrl, arrow-up etc then the onkeydown() event fires.
  3. onkeypress()- This events works when I click on certain keys on the keyboard. It is similar to onkeydown() but differs in that it does not allow just any key. Cmd or ctrl will not fire the onkeypress() event but any bracket, letter or number will definitely fire the event.

And that is the end of it, now the next time I think, oh yah konje what do those onkey… what what events do, I will look for this post right here.

Shap, shap mieliepap!

--

--

Xoliswa Nongcebo Shandu
0 Followers

Very important lady developer, multiroller, ninawengcebo and random blogger.