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?
While annoying, it is not a bug that
onchange
is not fired until the element loses focus. (I get around the issue by having multiple bindings for different events; make sure not to clobber a handler and use an update aggregation if appropriate.)Here is the "official" W3C documentation on the subject:
Here is the MSDN reference:
The behavior, while often annoying, is as specified.
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
.IE does it after your input loses focus, which isn't until you click the button, tab out, or click somewhere else on the screen. Try onclick or one of the other events.
As far as i remember, IE doesn't handle onchange event the same maner as FF. The event will be fired when the mouse is clicked.
I advise you to use a library to handle events such as jQuery, Dojo, etc..
ohhh, I spent some time on that issue as well months ago. I came up with this solution for FF/IE onchange
As answered elsewhere, IE doesn't fire the event till you click outside the input field.
Just a quick expaination of how I fixed it with jQuery. (This is a translation of my code, so it may contain bugs...)
...was changed to...
For those new to jQuery you are basically waiting for the page to become fully loaded, then you are adding the event handler 'dosomething' to the input box.