Firefox caches form values

by jenny on 11 December 2008 - 06:25pm in

Firefox caches form values. Most noticeably, it caches the selected position on select boxes. I less often run into cached checkbox and radio button values... even the occasional cached text box value. If you're a developer, you will be familiar with this and its work-around -- clicking into the url box and hitting enter rather than refreshing while debugging.

Recently, however, I had a situation where my users were likely to run into this problem. In a view showing nodes with a certain status, there's a nice little select box to change the status via ajax. The user at this point often hits reload and watches the node with the new status disappear from the view, as expected, only to see the next node in the view appear to magically have been changed to the status of the node which just disappeared.

After being told about this "problem" with our form, my gut reaction was "duh, that's what firefox does -- tell them to click in the url bar and hit enter instead". I decided to at least attempt to be a little more user-friendly. Fortunately, it only took a second to google up this article and the excellent solution posted in the comments. You just call a reset() on the form on page load.

Using jquery, the solution looks like this:

$(document).ready(function() {
  $('#problematic_form').reset()
}

According to the same comment, if you actually have a reset button for this form on the page, some browsers will not allow you to call the reset function directly. In this case, you do a click() function on the button instead. I haven't run into this problem -- I never use reset buttons on forms!