0
Need help with storage
I have never used local storage. I want to keep last changes after closing browser, it should not reset after re-open website. https://code.sololearn.com/WoWrkm8BF4x8/?ref=app
9 Respuestas
+ 1
Salman B
it is simple just add value with key
localStorage.setItem(key, value)
key should be unique because there might be many different keys
Value - whatever you want to get next time when you open browser.
Don't destroy your localStorage key otherwise next time you won't get that value.
To get value from localStorage use getItem function like:
var value = localStorage.getItem(key);
//Here key should be same as you have stored in localStorage.
+ 1
Salman B
If you want to write when page load then write inside window.onload function
0
Learn localStorage From here
https://www.sololearn.com/learning/2197/
0
I have checked your link. But i am not getting how to use it in my code. Can you just help me out?
0
I tried this. Do it need to add function?
function myfunc(event) {
var fajr = document.getElementById("myP").value;
var zohar = document.getElementById("myZ").value;
var asar = document.getElementById("myA").value;
var maghrib = document.getElementById("myM").value;
var isha = document.getElementById("myI").value;
localStorage.setItem('ls_myP', myP);
localStorage.setItem('ls_myZ', myZ);
localStorage.setItem('ls_myA', myA);
localStorage.setItem('ls_myM', myM);
localStorage.setItem('ls_myI', myI);
};
0
Salman B
No need of function but if you are writing inside function then your function should be call once otherwise data will not be store in localStorage. Once data stores in localStorage then you can access anytime.
0
I don't want function then how to write this?
0
How to write this without Functions.
0
Can you please guide me. This is what i wrote. Code is long. I cannot post it here
function myfunc(event) {
var fajr = document.getElementById("myP").value;
var zohar = document.getElementById("myZ").value;
var asar = document.getElementById("myA").value;
var maghrib = document.getElementById("myM").value;
var isha = document.getElementById("myI").value;
localStorage.setItem('ls_myP', myP);
localStorage.setItem('ls_myZ', myZ);
localStorage.setItem('ls_myA', myA);
localStorage.setItem('ls_myM', myM);
localStorage.setItem('ls_myI', myI);
};