Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript event between onFocus and onChange

I'm working a web page where I'd like to run some JavaScript code when a user alters text in a given input field, but I can't figure out which event to trap (assuming one exists) that would give me the behavior I'm looking for. onFocus happens too soon -- if the user selects the field but doesn't change any text, I don't want anything to happen. But onChange is too late -- I'd like the JavaScript to fire as soon as the user starts typing, not when the user is done typing and clicks something else. How could I accomplish this?

like image 582
BlairHippo Avatar asked Aug 25 '26 09:08

BlairHippo


2 Answers

onkeydown (although it wouldn't work for pasted data, where onchange is probably better).

like image 137
Quentin Avatar answered Aug 26 '26 22:08

Quentin


There are a couple events that can help you:

  • onKeydown (fired when a key is pressed down)
  • onKeyup (fired when a key is released)
  • onKeypress (fired when a key is pressed and then released)
like image 25
Alex Weber Avatar answered Aug 27 '26 00:08

Alex Weber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!