Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input event triggered on Internet Explorer when placeholder changed

As it is shown in this jsfiddle example when i change placeholder it triggers input event. I tested it on I.E 11 version but i guess that older versions have same problem. The other browsers does not behave like this. Is this I.E bug ? If so what is workaround for this problem on I.E ?

Here is html markup.

<input type="text" />
<button>Change PlaceHolder</button>

And here is javascript part.

var i = 0;
$('button').click(function(){
  $('input').attr('placeholder','placeholder ' + i++);
});

$('input').bind('input',function(){
    alert('input even occur');
});
like image 304
Freshblood Avatar asked Jan 28 '14 12:01

Freshblood


People also ask

Which event is triggered when a form field is changed?

Whenever the value of a form field changes, it fires a "change" event.

How do you trigger an input event?

Use the dispatchEvent Method querySelector('input'); element. addEventListener('change', () => console. log('change')) const event = new Event('change'); element. dispatchEvent(event);

What is input event?

The input event fires when the value of an <input> , <select> , or <textarea> element has been changed. The event also applies to elements with contenteditable enabled, and to any element when designMode is turned on. In the case of contenteditable and designMode , the event target is the editing host.


1 Answers

checking if input is focused should be enough

$('input').bind('input',function(){
    if($(document.activeElement) != $('input'))
        return;
    alert('input even occur');
});

this also "fixes" the input event being triggered without any actions when placeholder contains an accented character

like image 62
Charly Koza Avatar answered Oct 25 '22 09:10

Charly Koza