KC Here KC Here -5 years ago 126
Javascript Question

How to make my upvote/downvote button store cookies and count votes only 1 time

Take a look at this https://fiddle.jshell.net/tnvv0dds/4/ I made this upvote/downvote button for my website, but it resets every time I refresh the website + it counts votes every time I click on it. I have no idea how to fix it since I am a bit new. Can someone make a javascript suggestion for me or give me a website link where I can learn it? I spent 3-4 days in searching it without success.

Answer Source

You can learn HTML5 Web Storage, and use them with the following code.

$(document).ready(function() {
    if(localStorage.getItem("count") == null)

var counter = 0;
  localStorage.setItem("count", counter);

  localStorage.setItem("count", counter);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download