简体   繁体   中英

Cache form data against page refresh

I have certain forms in my Django project and I want to get a different data with a button on this form with a pop-up window and save it to the database. But here, how can I make the previously entered data come back when the page is reloaded so that my background data is not lost?

Thanks in advance to everyone who helps.

LocalStorage has a setItem method. You can use it like this:

var inputEmail= document.getElementById("email");
localStorage.setItem("email", inputEmail.value);

When you want to get the value, you can do the following:

var storedValue = localStorage.getItem("email");

It is also possible to store the values on button click, like:

<button onclick="store()" type="button">StoreEmail</button>

<script  type="text/javascript">
  function store(){
     var inputEmail= document.getElementById("email");
     localStorage.setItem("email", inputEmail.value);
    }
</script>

To use cookie instead, you can refer to this article.

localStorage.setItem("name", "Smith");
localStorage.getItem("name");
localStorage.removeItem("name");

You can use localStorage, This data can be available in developer Tool=>application Tab => localstorage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM