0

I'm attempting to create a "like count" on this banner i'm working on. I've created a button and I have a number above the button that goes up on every click. However once the page is refreshed it goes back to 0 or if someone else opens the page it'll be on 0 for them as well. Is there a way I can make it save the count on the server side so that no matter where you open the website it continues from the count saved to the server? here's my code below, any help is very appreciated thanks.

<div class="likecount" id="clicks">0</div>

<input type="button" class="button1" onClick="onClick()" value="   Like   ">

and here is the javascript I have for the counter to work.

<script type="text/javascript">
var clicks = 0;
function onClick() {
    clicks += 1;
    document.getElementById("clicks").innerHTML = clicks;
};
</script>
  • What language are you using server-side? – pete Sep 30 '17 at 21:03
  • It's using apache – Higinio Melero Sep 30 '17 at 21:10
  • 1
    You need a server side language and a database (or a text file) You need to store the like on the server – mplungjan Sep 30 '17 at 21:13
  • By `Apache`, did you mean Perl? Python? In any case, @mplungjan is correct, you need something to store your `likes` in (like a database or a text file, server-side in either case), and a server-side language to get the likes from the database and emit them to the page. – pete Sep 30 '17 at 21:18

0 Answers0