Log in

View Full Version : Recalling data from file on click for count



nielse63
09-10-2009, 05:37 AM
I'm having some trouble figuring out how to fully configure my count on click code for my site. Right now, the function is that whenever a user clicks on a piece of text, the number next to it increases by one. The basic code as of yet is as follows:

Code:


<script type="text/javascript">
function add_to_mycounter(){
var mycounter=document.getElementById('mycounter');
var cstore = document.getElementById('counter_store');

cstore.value=parseInt(cstore.value)+1;
mycounter.innerHTML=cstore.value;
}
</script>

<a href="javascript:add_to_mycounter();">Add</a><input type="hidden" name="counter_store" id="counter_store" value='0'><span id="mycounter">0</span>



However, the problem is that any time the user reloads or revisits the page the count goes back to zero. I need to know how to store the count in a file or database and recall that count upon reload. And I would like it if the count could appear on other pages where the text appears. Any help would work.

Thanks!

forum_amnesiac
09-10-2009, 06:39 AM
If you want to keep this count continually increasing then you could use AJAX or PHP to store it in a file.

If you want to keep the count for a session the you could use a PHP Session variable.