Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
Trying to use localStorage to store user-inputted text in textarea, but Save and Reload buttons are not working

I'm trying to use localStorage to store user-inputted text in textarea - I have a Save button to save the data to localStorage and a Reload button to retrieve the data to localStorage.

However, even though I am receiving screen alerts and the console is telling me that the button is working properly, everytime I enter data into the textarea and click "Save", then delete the data and click "Reload", nothing reloads.

Curiously, it does reload if I refresh the page and click "Reload", but not if I'm on the same page continuously.

I am confused as to why - am I not using localStorage properly? Is there something wrong with my JavaScript functions?

Here is my code:

<html>
<head></head>
<body>
To Do:<p>
<textarea id="todo" cols="50" rows="10">
</textarea><p>
<button id="save">Save</button>
<button id="reload">Reload</button>

<script type="text/javascript">

//save entered info
document.getElementById("save").addEventListener("click", function ()
    {
        var todo = document.getElementById("todo").value ;
        localStorage.setItem("todo", todo) ;
        alert("Saved To-Do List") ;
        console.log("Saved To-Do List")
    } , false);

//reload last session
document.getElementById("reload").addEventListener("click", function ()
    {
        document.getElementById("todo").innerHTML = localStorage.getItem("todo");
        alert("Reloaded To-Do List") ;
        console.log("Reloaded To-Do List")
    } , false);
    
</script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Replace This line document.getElementById("todo").innerHTML ='Your code' to this document.getElementById("todo").value ='Your code' .

Try this code it's works

<html>

<head></head>

<body>
  To Do:<p>
    <textarea id="todo" cols="50" rows="10">
</textarea>
  <p>
    <button id="save">Save</button>
    <button id="reload">Reload</button>

    <script type="text/javascript">

      //save entered info
      document.getElementById("save").addEventListener("click", function () {
        var todo = document.getElementById("todo").value;
        localStorage.setItem("todo", todo);
        alert("Saved To-Do List");
        console.log("Saved To-Do List")
      }, false);

      //reload last session
      document.getElementById("reload").addEventListener("click", function () {
        document.getElementById("todo").value = localStorage.getItem("todo");
        alert("Reloaded To-Do List");
        console.log("Reloaded To-Do List")
      }, false);

    </script>
</body>

</html>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!