8

I'm having this issue specific to IE8. This event doesn't fire in IE8 alone, but is working fine in IE9 and other browsers like Firefox and Chrome.

$('#myId').on('input', function () {
   //do something.
}

Please let me know if there is any work around for the same in IE8.

Thanks!

user2721870
  • 195
  • 2
  • 3
  • 8

6 Answers6

27

Older versions of IE have an event called propertychange that you can use. You can check for the propertychange event and the input event at the same time:

$('#myId').on("propertychange input",function(ev){
    doAwesomeThing();
});
AaronBaker
  • 1,013
  • 11
  • 15
8

oninput is IE9+, that is why it does not work in IE8

MDN oninput

Feature         Chrome    Firefox    Internet Explorer    Opera    Safari
Basic support   (Yes)     2          9                    10       (Yes)
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • Note that IE9 also doesn't support `oninput` well, see https://stackoverflow.com/questions/6382389/oninput-in-ie9-doesnt-fire-when-we-hit-backspace-del-do-cut – John29 Sep 25 '18 at 15:35
5

AaronBaker's answer: Works for both IE8 and IE10(html5) as well as modern browsers... without double post of event

I would have used comment or upvote but rep too low.

$('#myId').on("propertychange input",function(ev){
    doAwesomeThing();
});
1

It looks like the input event is a part of the HTML5 specification, something I wouldn't expect IE8 to handle. You may need to use the change event instead.

villecoder
  • 13,323
  • 2
  • 33
  • 52
1

This slight optimization will prevent the listener from firing twice in modern browsers (kind of a hack, but prob the best solution)

$('selector').on(!window.eventListener ? 'keyup' : 'input', function () {}

0

I tried using propertychange as suggested by the top answer, but I noticed that sometimes it doesn't fire in IE8. For example after a page refresh with a prefilled input if I delete only one character.

My solution is to use keyup cut paste events instead of propertychange:

$('#myId').on('input keyup cut paste', function(e) {
    setTimeout(function() {
        doAwesomeThing();
    }, 0);
});

I used setTimeout with 0 delay because otherwise I would get the old input value on cut and paste events, see https://stackoverflow.com/a/9364812/2324685 for details.

You should note that this code might fire twice in some cases.

John29
  • 3,340
  • 3
  • 32
  • 50