W
W
WannaCreative2016-07-07 16:59:22
JavaScript
WannaCreative, 2016-07-07 16:59:22

How to save data from localStorage?

The data in localStorage is saved, but on reboot, it is not loaded

function save() {
  var savevalue = document.getElementById("MoneyBalance").innerHTML; 	
  localStorage.setItem('Money', savevalue);
}
function load(){
  var storedvalue = localStorage.getItem('Money');
  if (storedvalue) {
    document.getElementById("MoneyBalance").innerHTML = storedvalue;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-07-07
@WannaCreative

the problem is in if (storedvalue)
your storedvalue will not be true and false as you expect, but the value or "undefined". Accordingly, it should be like this:
or
if (typeof(storedvalue) !== "undefined")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question