Hi everyone, I am working on a web app with Vanilla JS,CSS and HTML. In my app, I have an input field where you shoud write your name; when you submit the value, it should be stored and shown on the front page/settings. After refreshing the page the value disappears. Why?
window.save_data = function () {
if (typeof (Storage) !== "undefined") {
let input = document.getElementById('inputName').value;
localStorage.setItem('name', input);
document.getElementById('inputName').value = localStorage.getItem('name');
let storedValue = localStorage.getItem("name");
document.querySelector("#user-name").innerHTML = storedValue;
console.log(storedValue);
return storedValue;
} else {
alert("Sorry! No Web Storage support..")
}
}
<input type='text' name="name" id="inputName" />
<button onclick="save_data()" type="button">Save</button>
Thank you in advance!
CodePudding user response:
Local Storgae is what you can use of for your scenario.
CodePudding user response:
To do this, please take a look and read about local storage ....