Disable Firefox's Auto-fill

Viewed 24898

Is it possible to disable Firefox's auto-fill feature without disabling auto-complete?

I know I can do this:

autocomplete="off"

But I don't want to disable auto-complete, just the auto-fill.

Firefox is populating some of our hidden fields which are meant to be empty

This is mostly a problem when the user refreshes the page. The form fields are re-populated with values from pre-refresh. An example of this being a problem is old-school place-holder. Where we populate the field with a value, and remove it on submit. The value is re-populated on refresh and we don't know if it's the place-holder or use value.

11 Answers

I had this problem myself. Mike's answer is close, but not perfect in my opinion: it empties elements, even if a value attribute may want to set it.

On pageload, I do the following. It uses only a little jQuery.

// Reset input elements to their HTML attributes (value, checked)
$("input").each(function(){
    // match checkbox and radiobox checked state with the attribute
    if((this.getAttribute('checked')==null) == this.checked)
        this.checked = !this.checked;
    // reset value for anything else
    else this.value = this.getAttribute('value')||'';
});

// Select the option that is set by the HTML attribute (selected)
$("select").each(function(){
    var opts = $("option",this), selected = 0;
    for(var i=0; i<opts.length; i++) 
        if(opts[i].getAttribute('selected')!==null) 
            selected = i;

    this.selectedIndex = selected||0;
}); 


No jQuery?

Use document.getElementsByTagName to select the inputs and selects, then iterate over them and replace this by the iterated element.
Select the options with .getElementsByTagName('option').

This actually works with a password field in FireFox:

$(window).load(function(){
    $('#pass').val('');
});
Related