Chrome 11+ (and possibly IE) doesn't launch OnChange after setting

A while ago, I wrote an input mask extension for jQuery that automatically filters out any values ​​other than decimal / integer from the input element, I just found that it no longer triggers the onchange event if the keyup event changes the input value:

Example: http://jsfiddle.net/At8Ht/37/

If you view this in Firefox, it will display “Halp!”. under the input after changing it, when the input is blurred / loses focus, but in Chrome it is not.

Does anyone have any suggestions? In fact, all I'm trying to do is automatically insert commas when the user types a large number, for example, typing in “1552” gives “1,552” after the user released the key “2”. This worked fine until Chrome 11/12 :(

+3
source share
4 answers

You can do this with blurand a little more details:

$("#item")
    .focus(function() {
        this.previousValue = this.value;
    })
    .keyup(function() {
        this.value = new Date().getTime(); // or whatever magic code goes here
    })
    .blur(function() {
        if (this.previousValue !== this.value) {
            this.previousValue = this.value;
            $('#console').append('halp');
        }
    });

Jsfiddle demo

+2
source

Change changetoblur

$("#item").blur(function() {
    $('#console').append('halp');
});

UPDATE:

$("#item").blur(function() {
    $('#console').append('halp');
    $(this).trigger('change'); //trigger change
});
+2
source

EDIT: ? ( , = "NOPE!" ).

$("#item").focus(function() { this.oldValue = this.value; })

$("#item").keyup(function() {
    $(this).get(0).value = 'NOPE!';
}).blur(function() {
    if(this.value != this.oldValue){
        $('#console').append('halp');
        $(this).trigger('change'); //trigger change
    }
});

(OLD VERSION) ,

.bind('keyup', function() {
    $('#console').append('halp');
});

(, firefox "halp!", , )

+1
source

This is a very simple example of this problem ... it is fixed in chrome 14 ... but before 13 there is a problem ...

see example ... works even in IE, but not in chrome.ver <14

http://jsfiddle.net/nWVeX/7/

The easiest solution is to use blur instead of changing ...

0
source

All Articles