0

I'm looking for a way to change a number on a page on refresh. Let's say you have W.001 to start with and every time someone refreshes, it changes to the next number in sequence. So: W.001 (refresh) W.002 (refresh) W.003 and so on. Anyone got any ideas?

The website would be hosted locally, no need to host it anywhere else.

Someone pointed me to JS cookie but, I'm a total newbie to this.

If someone would be able to write me a simple index.html file that showcases how this works, it would help me a lot!

Opal
  • 81,889
  • 28
  • 189
  • 210

2 Answers2

0

There are infinite tutorials and examples on this, I would recommend searching the community before posting a question.

What you're going to want to do is create / get a cookie via javascript.

Please see

How do I create and read a value from cookie?

Set cookie and get cookie with JavaScript

If you still have questions after looking through these, post back with your attempted solutions and anyone should be more than happy to help

Community
  • 1
  • 1
chrismillah
  • 3,704
  • 2
  • 14
  • 20
  • Hi r00k, thanks for your reply! I had found these links, but didn't understand how to make that value show up in the body, that's why i posted a new question... – Jonas De Ruytter Apr 27 '15 at 17:43
0

Is it needed that the server gets the value? If you just want to save it locally and show it on the page, localStorage is better suited and really easy to use. The value will be stored between sessions.

// increment the counter
if (localStorage.counter) {
    localStorage.counter += 1;
} else {
    localStorage.counter = 1;
}

// add it to the page
document.getElementsByTagName("body")[0].innerHTML += localStorage;
bmesuere
  • 502
  • 3
  • 12
  • No need that he server gets the value! This would do the trick! So if i'm correct (as i said, total noob) // increment the counter (goes in head, between script tags, right?) // add it to the page (goes in body?) – Jonas De Ruytter Apr 27 '15 at 18:37
  • Thanks for the suggestion btw, I've been struggling all day – Jonas De Ruytter Apr 27 '15 at 18:54
  • To be safe, put the first part in the head between script tags, and the other line at the bottom of the body between script tags. – bmesuere Apr 28 '15 at 07:16