page remembers value on refresh

perkeyone

something clever
Reaction score
71
when i initially load this page it gives 2 alert messages. "0" and then "1"
on refresh it alerts "1" and then "2"...
why?
i am expecting it to be reset to 0 and 1 each time but it doesnt.
PHP:
<?php
echo "<input type=\"hidden\" value=0 id=\"selectcount\" name=\"selectcount\"/>";
echo "<script language=\"javascript\">alert(document.getElementById(\"selectcount\").value)</script>";
echo "<script language=\"javascript\">++document.getElementById(\"selectcount\").value</script>";
echo "<script language=\"javascript\">alert(document.getElementById(\"selectcount\").value)</script>";
?>

EDIT: this problem doesnt occur in ie but does in firefox
EDIT2: it seems to be a cache issue. i found that a "hard refresh" avoids the problem.
i am still looking for a way to fix this in my code though, since i didnt know how to hard refresh till about 3 min ago.
EDIT3: as a temporary fix, i am using javascript to manually set the input to 0 each time the page loads. id really like to find a true fix for this issue though.
 

perkeyone

something clever
Reaction score
71
no good.
i need to know how to prevent it from caching.
i did some google searches but found mostly information from a few years ago when firefox3 came out, so im not sure if any of it still applies to the most recent version.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
PHP:
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>

From the PHP manual.
 

perkeyone

something clever
Reaction score
71
i put the two lines lyerae gave in my index page before my include statements. now my page only seems to work the first time it loads. =/ im sure this is just some rule i forgot about how headers work... i know theres a certain time where you should and shouldnt use them because it messes with output or something... idk. anyways, what would be the best place to put those lines?

at least one of my functions broke after adding those lines. i have a js function which adds a select box to my form. the select box is labeled according to how many select boxes there are. (box 1, box 2, etc) after i added those headers, the select boxes are only added the first time the page loads. also, when i tried debugging i found that it still remembers how many boxes there were, which is the thing i was trying to prevent when i added those lines in the first place. =/ i think maybe i didnt put them in the right place. upon further inspection i found that the function was not working because the value is in the cache... the incorrect value is causing the function to try to access elements that dont exist.

here is the page i am using to test with.
i placed the two lines in the equivalent place.
the value is still remembered.
PHP:
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
include("entry_functions.php");
include("resourcelibrary/functions2.php");
rlConnect();
?>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
<script type="text/javascript" src="entry.js"></script>
</head>
<body>
<?php
echo "<input type=\"hidden\" value=\"0\" id=\"selectcount\" name=\"selectcount\"/>";
//echo "<script language=\"javascript\">document.getElementById(\"selectcount\").value=0</script>";
echo "<script language=\"javascript\">alert(document.getElementById(\"selectcount\").value)</script>";
echo "<script language=\"javascript\">++document.getElementById(\"selectcount\").value</script>";
echo "<script language=\"javascript\">alert(document.getElementById(\"selectcount\").value)</script>";
?>
</body>
</html>
 

Slapshot136

Divide et impera
Reaction score
471
normal f5 is refresh, but if you do control or command + f5, then it should override the cache (in Firefox), does this work for you?
 

perkeyone

something clever
Reaction score
71
yeah i already know hard refresh will work.
but i cant expect other people who would use the page to only hard refresh.
 

celerisk

When Zerg floweth, life is good
Reaction score
62
Form elements should be inside a "form".
language="javascript" has been deprecated several years ago already.
You should set a "doctype".
You do not need php to output a static line of javascript...


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
<script type="text/javascript">
function foo()
{
    document.getElementById("selectcount").value++;
    alert(document.getElementById("selectcount").value);
}
</script>
</head>
<body onload="foo()">
<form method="post" action="#" [B]autocomplete="off"[/B]>
<p>
<input type="hidden" value="0" id="selectcount" name="selectcount" />
</p>
</form>
</body>
</html>

Note the autocomplete="off", that should help.
And, yes, Firefox... the older it gets the more it becomes a PITA.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
What is it exactly that you are trying to achieve?

Can't really see as you edited the OP several times before I read this thread.
 

perkeyone

something clever
Reaction score
71
@celerisk
the code that i have posted is just my test page.
i made the test page so that i could experiment with different proposed solutions,
without the risk of causing further complications.
my real code is dynamic, but since i copy pasted from it to the test page, it's now out of context

turning autocomplete off solved my problem,
but is that the only way to fix this issue?
for some of my fields it might be useful to have autocompletion.

EDIT: i specified doctype and now my tables are a little messed up in firefox and significantly messed up in ie.
before i had it so they looked almost exactly the same. =[

@magentix
i have a hidden field in my form. some button calls a function which increments that hidden field.
if i refresh the page the field remains incremented.
my problem is, i want it to reset to the initial value if the user refreshes the page.
 

celerisk

When Zerg floweth, life is good
Reaction score
62
" the code that i have posted is just my test page. "

I guessed that much. There's just too many things missing :p


" but is that the only way to fix this issue? "

Probably, yes (other then getting a "better" FF).
You can put it on individual "input"s and remove it from the "form".


" i specified doctype and now my tables are a little messed up "

That is a perfect reason why you should always add one.
It means you found some problem.
Like an element that isn't closed but should or so.

And, well, you just never know what kind of browser your visitors are using.
As such, you should always present them valid code.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
Uhm, just set the field's value to zero using javascript...

With jQuery:
Code:
(function($){
    $(function(){
        $("#theinputbox").val(0);
    });
})(jQuery);

Edit: If you don't know jQuery, what it does is:
- pass the jQuery object to the local $-variable
- call the $(document).ready() function (shorthand is demonstrated here)
- set the field's value to zero

This will work on any refresh: hard or soft
 

perkeyone

something clever
Reaction score
71
@magentix
yeah i know,
ive been using javascript to reset it manually already from at least as early as post #9 of this thread, but not using jquery.
thanks though, your idea would work.
i just wanted to find some other ways.
 

celerisk

When Zerg floweth, life is good
Reaction score
62
" from at least as early as post #9 "

Well, as seen in post #1:
" EDIT3: as a temporary fix, i am using javascript to manually set the input to 0 each time the page loads. id really like to find a true fix for this issue though. "



" never seen that syntax "

It's for the paranoid that still want to use $ for jQuery even if the page already includes some other javascript library that remaps $.
Read the documentation (second example).

(function...)() is a function (obvious) that executes itself immediately once loaded (because of the () at the end).

Stupid example:
var five = (function(){ return 5; })();
Is equivalent to
var five = 5;

It has its uses at times :p
 

perkeyone

something clever
Reaction score
71
@celerisk
i edited the op several times, at least one of those edits happened after he posted, so i gave him the benefit of the doubt that it wasnt in the op when he read it. post 9 however has been there for a while, but it is very easy to not read a line that is commented out, especially since i didnt put any other comments in there to describe what was trying to accomplish. so i didnt mean to bust him out, i only meant to say that i figured that much out at least.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top