Is it possible with only one bind to either keyup, keypress or keydown to find out that the field value has been changed?
I mean – some key presses don’t change the value (like pressing left arrow) and some do (like pressing any letter-button or backspace).
So is it possible to know that key press caused the value change having only one binding?
PS: yes, I realize I could save the value somewhere and compare it in the very begin of event handler, but is there a solution without temporary variables?
I don’t think so. I mean, you can map key codes that you assume will be silent, but that map might not be 100% reliable as the input value can change or loose focus depending on how the OS and browser is set up.
Is there a special reason for not detecting change via a variable? It seems like the most reliable thing since this is also exactly what you need to detect:
If you don’t want to use stray variables, how about saving it in the
dataattribute?Update based on your comment
You can also use the
inputevent (in modern browsers) to detect change if you don’t care about keys:The last option would be to use an interval and keep checking the input field (this might be the most reliable option).