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.
Asked
Active
Viewed 369 times
-1
-
Please include the code you have tried so far. – Rohit Poudel Jul 09 '17 at 06:24
4 Answers
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
You need to use cookies, sessionStorage, localStorage, or query parameters.
Please take a look at these similar questions:

Miguel Mota
- 20,135
- 5
- 45
- 64
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