Jump to content

Button counter save

Recommended Posts

Hello, so i have this button that counts every time you tap it, but whenever you refresh or closes the tab it resests.

I've been trying for so long to find a way for it to save your progress, but nothing seems to work. Can u help me?


<div style=" text-align: center;" 
<h1>Hello my friend if you love chocobos, then you are the right place</h1>
   <script type="text/javascript">
   var Love = 0;
   function onClick() {
       Love += 1;
       document.getElementById("Love").innerHTML = Love;
   <input type="image" src="heart.png" onclick="onClick ()" width="62" height="62" />
   <p>Love given: <a id="Love">0</a></p>


Edited by Mellow

Share this post

Link to post
Share on other sites

You require a server side database (PHP/MYSQL is one option) with minimum columns ID, counter_name, count, on every click of button, it would send ajax request to a php page, this php page will update by incrementing the number in count column count=count+1 to a specific ID, afterwards this value is retrieved with SELECT query and echo the same the php page, this is returned back to the page where click event occurred, where it would update the value within element with id 'Love'.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now