Home > Enterprise >  How do you link a textbox to localStorage in HTML/JS?
How do you link a textbox to localStorage in HTML/JS?

Time:08-12

I'm trying to build a little web app that saves things you type to a localStorage variable. Here's some of my code so far:

<center> 
        <textarea style="background-color:#34373c; color:white; border:0px solid #34373c;" id="docbox" name="docbox" rows="100" cols="100"></textarea>
    </center>
    <script>
      localStorage.setItem('docbox', docbox);
      localStorage.getItem('docbox');
    </script>  
</center>

I was thinking some sort of tag but when you open the HTML and look at the console and type localStorage.docbox it tells you that docbox is a text box. I want it to tell me it's in the text box.

Thanks!

CodePudding user response:

I don't think you can store objects on a localeStorage, only strings, you'd have to stringify your object and de-stringify to extract.

How to store objects in HTML5 localStorage

CodePudding user response:

If you want to save the content of the textarea, you need to use the value.

docbox.value

  • Related