jfroom
jfroom

Reputation: 660

disable autocomplete/pre-populate in IE via HTML?

Demo link: http://elevation-inc.com/dev/test/ieform/

In IE 6/7/8 - if you enter a term into a simple input field, submit the form and then hit the back button - the input field retains the previously submitted term. If you then refresh the page, the value is also retained.

How, via HTML, can this pre-population be disabled? We want no value to be in the input box on page load/domready.

We've already tried autocomplete='off' on both the form and input element, but the pre-population is still persisting.

Thanks in advance.

Upvotes: 3

Views: 4677

Answers (3)

Eduardo Molteni
Eduardo Molteni

Reputation: 39413

This is how IE works, but you can change the value with JavaScript

<body onload="document.getElementById('q').value = '';">
<form action="http://www.google.com/search" name="f" autocomplete="off">
    <input type="text" name="q" autocomplete="off" id="q"><input type="submit">
</form>

Upvotes: 3

Gert Grenander
Gert Grenander

Reputation: 17084

<input type="text" name="userid" autocomplete="off" /> works fine for me (the same goes with your form). Make sure you reload the page in between testing (CTRL + F5 for full refresh).

Upvotes: 5

gblazex
gblazex

Reputation: 50101

Well I guess it's a browser behaviour you can't bypass by html. You can do it in javascript however:

<script>
window.onload = function() { document.forms.f.q.value = ""; };
</script>

or if you don't want to wait for images to load (because window.onload will wait for that), you can use the document ready event, as described here. (it needs more tweaking to make it work across all browsers)

Upvotes: 2

Related Questions