Today while working on one of the requirement, I encountered strange thing about onChange event behavior in Internet Explorer 7 and Mozila Firefox 3.

Actually my requirement was to show and hide div based on the radio button selection. I was having following code on "onChange" event of the radio button,



Code was executing very well on Mozila and everything was fine, But same stuff was working unexpected in Internet Explorer. According to the code , DIV A should visible if "Yes" was selected else DIVB should be visible. When I ran the code in IE, On selection of "yes" nothing was happening , but on selection of "No" DIV A was getting visible which was wrong. However that's the way "onChange" event should work but why Mozila is showing correct DIV on onchange event. I didn't got the answer by myself or even from the Google.

After few attempts, I didn't put much attention and put the code in "OnClick" event of the radio and it works well in both the browser. Just forsake checked in Google , found many people experienced the same. Anyways I had other stuffs to do so left there it is..

Would love to know if anybody get the answer :-)

4 Responses to "OnChange event behavior in IE and Mozila"

  1. gravatar Dragon Cotterill Says:

    The inchange feature only triggers once focus of the field has been lost. Onclick is immediate.

  2. gravatar J E Carter II Says:

    Also, it would help your efforts if you looked into prototype.js or jquery which can help resolve a lot of browser incompatibilities you are bound to encounter with JavaScript and CSS through the abstraction provided by each library.

  3. gravatar Rishi Says:

    @Dragon, Yes I know well about OnChange event triggering. But What I surprised why it's not the same way happens in Mozila.

  4. gravatar Rishi Says:

    @Carter, I am using dojo framework, but still event handling is same in most of the framework.What do you say?

Leave a Reply

preload preload preload