Somebody
Somebody

Reputation: 9645

jQuery IE7 / IE8: Prevent change event triggering on Enter

Here is sample code:

http://jsfiddle.net/BSjGX/1/

<input id="testing" />

$('#testing')
    .keydown(function(e){
        if(e.keyCode==13) {return false;}
    })
    .change(function(){
        $('body').append('<br />changed');
    });

How do you ppl doing it in IE7 / IE8 etc?

Thanks ;)

Upvotes: 1

Views: 808

Answers (2)

andyb
andyb

Reputation: 43823

The change() event is firing when the <input>s value is changed. The value is updated when the <input> loses focus. You could add a blur() handler to intercept the "change".

Upvotes: 0

Jeff Sheldon
Jeff Sheldon

Reputation: 2094

Problem is, that the fact that it's changed has already occurred before your code is used.

So you can eat the change, but then on blur, it won't react that it's changed. Try this:

$('#testing')
    .change(function(e){
        if (e.keyCode == 13) {
            e.preventDefault();
            return false;
        }
        $('body').append('<br />changed');
    });

I think you'll see what I mean. I think to do what you want, you might need to have your own variable, and track changes.

Upvotes: 1

Related Questions