views:

43

answers:

4

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.

+1  A: 

<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).

Gert G
A: 

Hi, maybe you could try to reset your form on dom ready.

greg0ire
+2  A: 

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)

galambalazs
This seems to be the best approach when it's coupled with the onDomReady event. However, would need to store focus state in a var to ensure that user entered text wasn’t being wiped out by the above script accidentally. I recall encountering some issues with not being able to detect focus state accurately if the user had given focus to the form element before the script had loaded, which would complicate this approach. But that might be resolvable. More comments to follow..
jfroom
Luckily for our app, there was an alternate approach we could take instead of clearing out the field. Instead, we check to see if the field has a value onDomReady and trigger dependent functionality based on if it's empty or not. Was just hoping there was an easier way to kill that IE prepop ‘feature’ via HTML.
jfroom
well there is no reason to differentiate. onDomReady value="" should do. If there is no content, nothing happens, if there is content it will be removed.
galambalazs
but it runs only once. anything the user types after document is ready, will not be wiped.
galambalazs
Thanks galambalazs, but I think there is reason to differentiate. The user could have typed something into the field _before_ the dom ready event triggers, in which case the above script will wipe their intentional entry. This can happen on large content pages and especially with older browsers. However, I think this thread is on the best path for this question topic, so I'll mark it as the 'answer'. Thanks for your time.
jfroom
A: 

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>
Eduardo Molteni