IE doesn't fire input event on delete

I am trying to put some placeholders on a form. They work fine in Chrome and Firefox, but I can't seem to get them to work on IE (I'm testing this with IE9). The problem is that the input event only fires when text is added to the input, not when it is deleted (using delete key, cut, right click, etc.).

This is my code (uses jQuery):

$input.on('input propertychange', function() {
    if($input.val() == '')
        $placeholder.show();
    else $placeholder.hide();
});

      

I read that this might be a known issue. If so, are there any workarounds?

Thank you for your help.

+3


source to share


2 answers


If you want to test for special keys, you must go with keyup:

http://api.jquery.com/keyup/

$('input').keyup(function(e){
   if (e.keyCode == 13)
      console.log('enter!');  
});

      



If you just want to fire an event on any changes, you must go with a change event:

http://api.jquery.com/change/

$('input').change(function(){
   //When it changes
});

      

+1


source


Try using event keyup

. This is checked every time the user releases the key, so this is a pretty consistent hit test for delete and cut combinations, etc.



0


source







All Articles