Mellow Posted May 31, 2018 Share Posted May 31, 2018 (edited) 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? <body><div style=" text-align: center;" <h1>Hello my friend if you love chocobos, then you are the right place</h1><br> <script type="text/javascript"> var Love = 0; function onClick() { Love += 1; document.getElementById("Love").innerHTML = Love; }; </script> <input type="image" src="heart.png" onclick="onClick ()" width="62" height="62" /> <p>Love given: <a id="Love">0</a></p> </div> Edited May 31, 2018 by Mellow Link to comment Share on other sites More sharing options...
dsonesuk Posted May 31, 2018 Share Posted May 31, 2018 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'. Link to comment Share on other sites More sharing options...
JMRKER Posted July 18, 2018 Share Posted July 18, 2018 Unclear on the request, so for clarification: Does the button count need to be stored on the server for counts from more than one user? Or, can the button count be saved (and/or reset) with local storage on the users single computer? Link to comment Share on other sites More sharing options...
dsonesuk Posted July 18, 2018 Share Posted July 18, 2018 The count is stored in a single row with a id ref, and probably a count identifier if you have more than one counter on a database, local storage stores data specific to the user visiting a site, it will never able to register and update other users triggering a count event. Every time someone clicks the button or whatever, it goes to the database and increments the current value by 1, the current total result is then retrieved and shown on the website. Link to comment Share on other sites More sharing options...
JMRKER Posted July 19, 2018 Share Posted July 19, 2018 On 7/18/2018 at 5:14 PM, dsonesuk said: The count is stored in a single row with a id ref, and probably a count identifier if you have more than one counter on a database, local storage stores data specific to the user visiting a site, it will never able to register and update other users triggering a count event. Every time someone clicks the button or whatever, it goes to the database and increments the current value by 1, the current total result is then retrieved and shown on the website. Sorry, I understood your suggestion. I have used it in the past as well. What I was asking the OP for was clarification as to how the count request was to be used. Server (your solution) or client side (via local storage). Link to comment Share on other sites More sharing options...
dsonesuk Posted July 20, 2018 Share Posted July 20, 2018 Local storage is not practical as it would not store anyone else's click count but your own, it would not sync with anyone's else's clicks or the current total of clicks. Link to comment Share on other sites More sharing options...
JMRKER Posted July 20, 2018 Share Posted July 20, 2018 8 hours ago, dsonesuk said: Local storage is not practical as it would not store anyone else's click count but your own, it would not sync with anyone's else's clicks or the current total of clicks. Sorry, but I did not see any requirement from OP that the code requested needed to be on a server, hence the initial question. Obviously the OP has his/her answer or has given up. Either way, no need to argue about requirements when either could work if there were more request clarification. Link to comment Share on other sites More sharing options...
dsonesuk Posted July 20, 2018 Share Posted July 20, 2018 If the OP wants to play button clicking by him/her self, the OP can find exactly want is required here https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_localstorage2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now