0

I cannot figure out what I am doing wrong. When the save button is clicked it is supposed to send the text from the textarea into local storage. Then when you close and reopen the page the text that was saved is supposed to come back. But when I close the document and open it again, it is blank. Is there a mistake that I am overlooking, or should I try a different method to save to local storage?

<script>
function save () {
    var inputvalue = document.getElementById('textfield').value;
    localstorage.setItem('text', inputvalue);
}

function load() {
    var storedValue = localStorage.getItem('text');
    if(storedValue) {
        document.getElementById('textfield').value = storedValue;
    }
}
</script>
</head>

<body onload="load()">
 <textarea id="textfield">
 </textarea>
 <input type="button" value="Save" onclick="save()" />
</body>
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user1927513
  • 61
  • 1
  • 4

0 Answers0