1

I have an <input> element which receives a default value (i.e. 180) on page load.

<label id="tl" class="secondary_text" title="title">Time limit [s]</label>
        <p>
          <input id="spinner-timelimit" class="spinner-ten" name="spinner" value="180">
        </p>

If I modify the original value (manually or using a jQueryUI spinner), the new value is stored, even after I refresh the page using F5. I'd like for the default HTML value to be reapplied after reload of the page, not the one that was input by a user.

I don't believe this is an ordinary cache problem, as I have disabled cache in the Firefox console, under Network tab.

I tried reproducing the situation in a JSFiddle, but there the refresh using Run correctly restores the default value, so doesn't reproduce the problem.

Note that this only happens in Firefox, not in Chrome. Can anything be done to force the HTML refresh in Firefox?

sc28
  • 1,163
  • 4
  • 26
  • 48
  • 1
    Have you tried using `autocomplete="off"` as per [this question](https://stackoverflow.com/questions/1799899/html-input-value-kept-after-refresh). Also note that the `input` is missing a `type` attribute. – Rory McCrossan Nov 27 '17 at 15:55
  • @McCrossan `input` type is implied as text if not specified. – jhpratt Nov 27 '17 at 16:00
  • Have you tried using tags related to caching in the header? As stated earlier, I would go ahead and explicitly denote the "type" attribute as text. –  Nov 27 '17 at 16:05
  • You could perhaps with jQuery set the default value of the input when the document loads? Hacky but should work? $(document).ready(function() { $("#spinner-timelimit").val(180); }); – Fred John Nov 27 '17 at 16:19
  • @Rory McCrossan @codemaker : thanks for these ideas, but `autocomplete="off"` didn't work, nor did setting the `type="text"`. However, setting `type="number"` has an odd consequence: it enables the "storing" of another separate value. So if I modify the value to N without specifying type, N gets loaded on refresh. Then if I modify the script with `type="number"` and enter a new number M, then M gets loaded on refresh. If I modify the script back, then N returns, and if I add again the type, M comes back. All without cache enabled! Any explanations for this? Might it come from jQueryUI? – sc28 Nov 27 '17 at 18:35
  • @jhpratt correct, but it's still a required attribute for compliance – Rory McCrossan Nov 27 '17 at 20:14
  • Compliance with what, HTML5? It is explicitly optional in HTML5. It was required for XHTML, however. – jhpratt Nov 27 '17 at 20:33
  • @Rory I tried again today and actually the `autocomplete="off"` worked, not sure why it didn't yesterday. Apparently the linked question hinting to this solution isn't technically a duplicate, as the question there is to prevent the behaviour _without_ editing the `input` form. So if you want to post the answer here I could accept it. – sc28 Nov 28 '17 at 11:19

1 Answers1

0

It might be because you are using reload() and there is bug with that method and cached input values in Firefox. Instead, this worked for me, with the same end result:

window.location.href = window.location.href;

Source: https://stackoverflow.com/a/18967757/1003472

Capripot
  • 1,354
  • 16
  • 26