Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE8 & IE7 onchange event is triggered only after repeated selection

I have a group of radio with an onchange handler:

<input type="radio" name="Q12" value="radio" id="Q12_0"  onchange="nextPnl('Q12');">
<br/>
<input type="radio" name="Q12" value="radio" id="Q12_1"  onchange="nextPnl('Q12');">
         ​

function nextPnl(did)
{
document.write(did);

}​

The problem is that in IE8 & IE7, the onchange event is triggered only after repeated selection.

Please view this demo in IE's Developer Tools [Browser Mode] IE8: http://jsfiddle.net/3zwur/2/

like image 729
Registered User Avatar asked Jun 17 '12 01:06

Registered User


People also ask

Can I install IE8 on Windows 10?

No, you cannot install IE8 on Windows 10. If a website will only work with IE8, open Developer Tool from F12. On the Emulation tab, set User Agent to be IE8.

Does IE8 still work?

This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

What is IE6 and IE8?

IE6 (in non-quirks mode): You write CSS for the IE6 limitations (hacks upon hacks) and sleep poorly. IE8 (in IE8/non-quirks mode): You write CSS which is [generally] compatible with other modern browsers and have happier dreams :p~ – user166390.

Is IE6 still used?

Internet Explorer 6 was the last version to be called Microsoft Internet Explorer. The software was rebranded as Windows Internet Explorer starting in 2006 with the release of Internet Explorer 7. Internet Explorer 6 is no longer supported, and is not available for download from Microsoft.


1 Answers

This is due to a bug with IE7 and IE8's change events. You should instead listen to the click event.

As shown in this table on quirks mode, the change event on radio buttons and checkboxes is quite buggy in IE7 and IE8.

You can listen to the click event like so:

<input type="radio" name="Q12" value="radio" id="Q12_0"  onclick="nextPnl('Q12');">
<br>
<input type="radio" name="Q12" value="radio" id="Q12_1"   onclick="nextPnl('Q12');">

And a fork of your fiddle: http://jsfiddle.net/T7VYL/

Usually, using a javascript library such as JQuery and YUI make your life easier, although from my testing, they do not fix this bug in older versions of IE.

If you would still like to listen to the change event, you can deploy this fix: http://www.ridgesolutions.ie/index.php/2011/03/02/ie8-chage-jquery-event-not-firing/. Basically it listens for the click event, and then causes the element to fire a change event.

As demonstrated by the asker's fiddle: http://jsfiddle.net/3zwur/3

like image 129
F21 Avatar answered Sep 30 '22 19:09

F21