HTML5, CSS3, jQuery, JSON, Responsive Design...

JavaScript onchange event and IE’s Autocomplete feature don’t mix

Michael Brown   March 31 2011 01:24:58 AM
Yes, IE's wonderful Autocomplete feature, the main goal of which is, apparently, to reveal your credit card details to the next person to use the browser after you.  If that's not bad enough, it seems that this feature has another less than endearing side effect: it screws up the onchange() event in IE too.

Autocomplete in Internet Explorer 6


The Problem

I have a project where I'm triggering certain functions on the browser's onchange() event, and I was putting those functions directly into the equivalent section in the Domino Designer, like so:

Onchange event in Domino Designer

More fool me.  I had read that this event is buggy in IE, but it passed all my system tests so I used it anyway.  Then somebody tested it that had the Autocomplete feature turned on in IE, and we found that the onchange() event simply doesn't trigger if that's the case.


Solution

The solution, which I'm currently still testing, is to remove such functions from the onChange() section in the Domino Designer entirely and add them using jQuery instead.  Here's the equivalent code to add a function to the field's onchange() event using jQuery:

            $("input#TestField").change(function() {
                    testFunction()
            });

The function should now trigger correctly whether IE's Autocomplete is turned on or not.  (I read that the jQuery people actually remap IE's onchange event to completely different events in the background to ensure it works properly.  And they do it in such a way that you, the developer, don't ever have to worry about it.)

I've put this code in my $(document).ready() function (in the JS Header).  FYI, the $(document).ready() is jQuery's equivalent of the form's unload() event; necessary because the latter is also completely unreliable.  (It fires a different times on different browsers, and even on different versions of the same browser.)  Once again, the jQuery people have made sure that $(document).ready() fires consistently on all browsers.
Comments

1C Penguin Esq  04/07/2011 12:00:39 AM  JavaScript onchange event and IE’s Autocomplete feature don’t mix

Get a life, maaaate.

About