Results 1 to 2 of 2

Thread: Recalling data from file on click for count

  1. #1
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Recalling data from file on click for count

    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:

    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!

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •