views:

350

answers:

1

If i dont put autocomplete="off" on my <input type="text" />s the browser will sometimes fill them in with likely/remembered data.

When does this happen in the DOM-load-lifecycle?

It appears to be after:

$(function(){ alert('i happen before autocomplete'); });

Is there a dom-load event which occurs after form-autocompletion?

If so, what is it?

If not, meh, what can I do to execute some JS "on page load", but after autocompletion?

Solutions needs to be cross browser

Thanks

Andrew

+2  A: 

You could give $(window).load(callback) a try. This will wait until everything is fully loaded (images etc), rather than just after the DOM has been loaded the way $(document).ready does.

I'm not 100% sure whether or not it happens before auto complete but it definitely occurs after DOM ready.

Alternatively you might try registering a "one-off" change event handler when the DOM is ready like so:

$(document).ready(function() {
    $('input').one('click', function() { 
        // do whatever you wanted to do when it first changed
    });
});

This will fire only the first time the field changes. The only question is whether or not the browser will fire the change event when it does the autocompletion.

TM
This works perfectly in every case except when you hit `Back` in Chrome. For this, i had to add a 100ms delay inside my window load function. Otherwise, fine :)
Andrew Bullock