Azat
Azat

Reputation: 681

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?

Upvotes: 3

Views: 385

Answers (3)

volpav
volpav

Reputation: 5128

Try subscribing to paste event:

Upvotes: 3

lonesomeday
lonesomeday

Reputation: 237817

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
});

Upvotes: 3

user57508
user57508

Reputation:

i would use blur for this

live demo

var control = $('#txt');
control.blur(function() {
    var defaultValue = control.attr('defaultValue');
    var actualValue = control.val();
    if (defaultValue != actualValue) {
        control.css('background-color', 'red');
    }
});

Upvotes: 0

Related Questions