Jump to content

Recommended Posts

I'm having some trouble with a click counter that's on my website.  Whenever a user clicks on "Good" or "Bad" the number next to it will go up by one, but the problem is that I can't figure out how to store the data for each click so that when the user returns the number remains at what it was (or is higher because other users have clicked on it).  As of right now the number is reset to 0 every time the page is reloaded.  Here's the code:

 

<script>
function add_to_goodcount1(){
    var goodcount1=document.getElementById('goodcount1');
    var cstore = document.getElementById('good_counter_score1');

    cstore.value=parseInt(cstore.value)+1;
    goodcount1.innerHTML=cstore.value;
}

function add_to_badcount1(){
    var badcount1=document.getElementById('badcount1');
    var cstore = document.getElementById('bad_counter_score1');

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

<a href="javascript:add_to_goodcount1();">Good </a><input type="hidden" name="good_counter_score1" id="good_counter_score1" value='0'><span id="goodcount1">0</span>
<p> </p>
<a href="javascript:add_to_badcount1();">Bad </a><input type="hidden" name="bad_counter_score1" id="bad_counter_score1" value='0'><span id="badcount1">0</span>

 

I'm looking to store the data onto a text file on the server, so that the number will be restored.  I'm pretty new to AJAX and PHP, so any help would be greatly appreciated.

 

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/174006-click-counter-ajax-help/
Share on other sites

Break it up.  There are like a billion "regular" counter tutorials out there.  Also, there are like a billion basic send/receive ajax tutorials out there.  Focus on making one that is not ajax based.  Once you have that sorted out, then focus on making it ajax based.

How would I write the PHP script so that it can be recalled?  I checked out counter tutorials and examples, and all of the ones that I wrote from there work great for recalling the number of hits, but I'm looking to collect data on the number of clicks and have that automatically posted.  Any hints?

 

Thanks.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.