I'm using the jQuery autocomplete plugin to get a list of locations, which works fine. But if the user clicks the browser's back button after submitting the page with the autocomplete textbox, the textbox is empty. If I take the autocomplete off the textbox and submit & click back it remembers the text.
Is there a way to stop the autocomplete from clearing the textbox when the page loads?
I had the same problem today, and found a way around this.
$("#search_form").submit(function() {
$("#location")[0].removeAttribute("autocomplete");
});
This code will remove the autocomplete attribute just before the form is submitted. You will have to change the selectors so that they match your form and input(s).
Well I found the issue. It seems to be on Firefox, not IE, and it's not technically due to the autocomplete plugin. It's because the plugin adds the attribute autocomplete="off"
to the textbox.
This is so that the browser's autocomplete history doesn't conflict with jquery's autocomplete, but in Firefox, fields that have this attribute don't get pre-populated when the user clicks the back button.
I'm guessing there isn't a way around this, it appears to be the default browser behaviour. If anyone knows different please post a comment.
in the $.autocompleter
function on the plugin there is a variable called previousValue
at line 72 of the unpacked version of the jquery.autocomplete.js
. This variable is set to an empty string on initialization.
If you're feeling ambitious, you could try editing this script and have if check if the textbox already has a value, and set previousValue to it if it does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With