How to keep the data of an html saved

2

Well, I need to get the value of a textarea and send it to a second textarea on the same page, but when I refresh I do not want the value to come from the second textarea sum, how to do this using javascript and Ajax? >

My Code

var textArea = getDOMElement("textarea", "class", "logarea", 0)
   var y = textArea.value;
   var x = document.createElement("TEXTAREA");
   var t = document.createTextNode(y);
   x.appendChild(t);
   document.getElementsByClassName("span8 center")[0].appendChild(x);
    
asked by anonymous 12.08.2018 / 23:21

3 answers

0

Use autoSave - A jQuery Plugin

<textarea class="form-control" rows="6" id="idTextArea" placeholder="digite aqui ..."></textarea>

<script>  
/*
 jQuery autoSave v1.0.0 - 2013-04-05
 (c) 2013 Yang Zhao - geniuscarrier.com
 license: http://www.opensource.org/licenses/mit-license.php
 */
(function(a){a.fn.autoSave=function(d,e){return this.each(function(){var b=0,c=a(this),f=e||1E3;c.keyup(function(){clearTimeout(b);var a=c.val();localStorage&&localStorage.setItem("autoSave",a);b=setTimeout(function(){d()},f)})})}})(jQuery);

var demoText = $("#idTextArea");


if (localStorage) {  
  var content = localStorage.getItem("autoSave");
  if (content) {
      demoText.text(content);
  }
}

</script>

Font

    
13.08.2018 / 04:55
1

Cookies

Cookies are data stored in small text files on your computer.

When a Web server sends a Web page to a browser, the connection is terminated and the server forgets everything about the user.

Cookies were invented to solve the problem "how to remember information about the user":

When a user visits a web page, their name can be stored in a cookie. The next time the user visits the page, the cookie "remembers" your name. Cookies are saved in name and value pairs, such as:

document.cookie = "username=John Doe";
    
12.08.2018 / 23:32
1

You can save the value of your textArea to the localStorage which is just like your na- tional database.

localStorage.setItem('textArea', y);

So whenever you load the page you can fetch the value in the localStorage and fill in your field:

x.value = localStorage.getItem('textArea');
    
12.08.2018 / 23:35