nielse63 Posted September 12, 2009 Share Posted September 12, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/174006-click-counter-ajax-help/ Share on other sites More sharing options...
.josh Posted September 12, 2009 Share Posted September 12, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/174006-click-counter-ajax-help/#findComment-917291 Share on other sites More sharing options...
nielse63 Posted September 12, 2009 Author Share Posted September 12, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/174006-click-counter-ajax-help/#findComment-917344 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.