Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript\jquery: Event that fires when textbox changes

I'm looking for a jquery/simple javascript (not some other library) solution that set an event to a textbox that will fire when the textbox being changed? (not after blur)
I need it to fire no matter how it was changed (keyboard char key/tab/enter or mouse paste) And I need it to be fired one time only.

like image 737
gdoron is supporting Monica Avatar asked Apr 27 '26 19:04

gdoron is supporting Monica


1 Answers

Unfortunately, there isn't one. There will be some day, when all browsers support the textinput event and/or the HTML5 input event, but currently not all do, and those that do have various bugs. You can use a combination of events, but you have to handle responding to each change only once yourself, and there's always the possibility of failing to cover some browser somewhere.

So if you absolutely, positively have to do this, you have to poll the value property every N milliseconds. (Choose the largest number you're happy with, to avoid making the browser work too hard, and make sure the code in the timer function is as tight and quick as possible — e.g., don't re-look-up the element each time, look it up once and keep a reference to it.)

like image 159
T.J. Crowder Avatar answered Apr 30 '26 08:04

T.J. Crowder



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!