-1

I have a variable named collar whose value is either red or green. It is used for random order as on or off. But in next page,it wont retain its previous value. How to do that. I am beginner in JavaScript.

4 Answers4

1

You may find this answer useful.Maintaing state in JS. You may use cookies to store the value.

Anup Kumar Gupta
  • 361
  • 5
  • 14
0

You need to use cookies or pass it to a server side back end using sessions.

Difster
  • 3,264
  • 2
  • 22
  • 32
0

All of the variables in Javascript only valid in an html page.
- When coming the another page, You may named same variable name but actually different variable.
- When the page is reloaded, the variable value is reset, current value is not kept.

If you really need previous value to be passed through next page, you can rely on server or local storage to keep the value and to be retrieve by the next page.

Khoa Bui
  • 733
  • 1
  • 7
  • 15