Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"onchange" event delayed in IE? (ok with Firefox)

It might be a beginner question but I can't understand why the onchange event is never called by IE while it works Ok with Firefox.

<input type="text" id="mytext" size="48" value="" onchange="execute()"/>
<button type="button" onclick="execute()">Go</button>

The execute function is called when the button is clicked but not when the text in the input box is changed.

Any idea?

like image 767
luc Avatar asked Oct 20 '09 13:10

luc


People also ask

Why is Onchange not working?

onchange is not fired when the value of an input is changed. It is only changed when the input's value is changed and then the input is blurred. What you'll need to do is capture the keypress event when fired in the given input. Then you'll test the value of the input against the value before it was keypressed.

How is Onchange triggered?

The onchange attribute fires the moment when the value of the element is changed. Tip: This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus.

Where we can use Onchange event?

Definition and Usage The onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed. Tip: This event is similar to the oninput event.


1 Answers

IE only fires the onchange event when the element loses focus - if you were to click outside the element or tab to a different element it should fire then.

You can get around this by using a different event, for example onkeypress.

like image 86
Greg Avatar answered Nov 07 '22 03:11

Greg