Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery 'change' event

How to detect changing of a text field when user inserts a text from the clipboard using mouse (trackpad)? 'change', 'keyup', 'click' events are not fired in this case. How it is done on Twiiter?

like image 233
Azat Avatar asked Dec 08 '25 09:12

Azat


2 Answers

If no traditional events work, you may have to set up some kind of polling system:

$('input').focus(function(){
    setInterval(function(){
        if (this.value != $.data(this, 'oldVal')) {
            $(this).trigger('change');
        }
    }, 250);
}).change(function(){
    $.data(this, 'oldVal', this.value);

    // do your onchange code here
});
like image 108
lonesomeday Avatar answered Dec 09 '25 22:12

lonesomeday


Try subscribing to paste event:

  • MDC reference
  • MSDN reference
like image 32
volpav Avatar answered Dec 10 '25 00:12

volpav