Forum Moderators: open
<input id="i21" name="c21" type="hidden" value=0 />
<input id="i22" name="c22" type="hidden" value=0 />
<input id="i23" name="c23" type="hidden" value=0 />
etc...
It works just as expected. However when a user refreshes the page using F5, the hidden values will not return back to 0. It will stay set at whatever it was previously.
Am I doing something wrong, or is there a way to force the values back to 0 when refreshed?
I think you'll find that it is not just the hidden fields. It seems to be normal browser behaviour in both IE6 and FF for ALL form fields (visible and hidden) to retain their values between page refreshes (F5). Unless the user hits Ctrl+F5, in which case the page is forced to be downloaded a fresh and the form values are reset.
You can of course initialise these values as the page loads and so 'resetting' any cached value. This may be the way to proceed?
Which browser(s) are you testing?
I don't believe this is an issue with Opera, as the form values appear to be reset on a regular page refresh.
I could have coded the entire page using Javascript variables instead of hidden inputs, but I had to hide some of my code using PHP in order to prevent some people from just viewing the source and copy+pasting it all.
I have around 800 hidden inputs on a single page, so doing some sort of FOR loop in a Javascript function will make the page load extremely slow. I already have a "Clear All" button that does the exact same thing, and it loads extremely slow on IE7.
Since I'm new here, I don't know the exact rules for this forum regarding whether I can post links to the page I'm talking about to give you a better idea of what I'm doing. But basically my page contains a table with about 800 cells, each with its own input.
It's kind of hard to explain, but people who use it seem to like the concept.
If there is a better solution to pass the status of each button to PHP, then I don't know it.
The 800+ inputs don't seem to pose a problem at the moment, seeing as the page loads and render fast.
But back to the original problem: Does anyone know a way to reset the hidden input values when the page is refreshed using F5? Looping through each input field is out of the question. I could always write a note on the page telling visitors to do [Ctrl+F5], but I'd rather make it easy for them and find a solution.
Looping through each input field is out of the question.
Have you tried it? I think you are underestimating the power of JS. I just tried 'resetting' 800 hidden fields using JS and it took 0.1 secs (on my P4 3.4 GHz). The bottleneck (if any) is not the JS, but the size of the page and the download time over a slow connection.
The code I used...
window.onload = reset_hidden;function reset_hidden() {
var el = document.getElementsByTagName('input');
for (var i=0; i<el.length; i++) {
if (el[i].getAttribute('type') == 'hidden') { el[i].value = 0; }
}
}
This will set the value of all hidden input elements to 0 when the page loads. Obviously you may have to tweak this if you have other hidden input's for other purposes.
However, you have to remember that I have a button associated with each hidden input, therefore using your method, we would be looping through 800 * 2 inputs since they are both tag name 'input'.
I just tested this out and it loads in 0.25 seconds using Firefox. However for IE7, it takes over 2 seconds. Would you feel comfortable adding 2 seconds to your page's loading time?
But I guess I'll have to live with it for now.
However, you have to remember that I have a button associated with each hidden input, therefore using your method, we would be looping through 800 * 2 inputs since they are both tag name 'input'.
In my example I did test it on a form with 800 buttons and hidden elements, so yes it was stepping through 1600 elements.
I just tested this out and it loads in 0.25 seconds using Firefox. However for IE7, it takes over 2 seconds. Would you feel comfortable adding 2 seconds to your page's loading time?
Admittedly I had only tried it in FF. IMHO, an extra 2 seconds on the page load time would be acceptable under the circumstances. How long is your page currently taking to download, without the form reset?
Another option might be to disable the page cache, but I think that would impact your page load time a lot more!
How long is your page currently taking to download, without the form reset?
2 seconds is a lot to me, thats why I'm so hesitant to use that Javascript loop.
I tried to disable page caching, but it didn't work.
>> P4, 3.4Ghz, 1GB, WinXP SP2
FF1.5 - 0.11 secs
IE6 - 0.74 secs
Op8 - 0.02 secs
>> T5300, 1.73Ghz, 2GB, Vista
FF2 - 0.08 secs
IE7 - 0.59 secs
Op9 - 0.02 secs
>> P2, 300Mhz, 224MB, Win98 (worst case)
FF1 - 1.05 secs
IE5 - 30.82 secs!
Op7 - 5.05 secs
FF and Op are certainly the winners in this test... IE5 is just of historic interest (good grief)!