const userName = document.getElementById("nameField");
const userEmail = document.getElementById("emailField");
const userDateOfBirth = document.getElementById("dateField");
//Wnen out of focus - set localStorage
userName.addEventListener("focusout", (event) => {
localStorage.setItem(event.target.id, userName.value);
});
userEmail.addEventListener("focusout", (event) => {
localStorage.setItem(event.target.id, userEmail.value);
});
userDateOfBirth.addEventListener("focusout", (event) => {
localStorage.setItem(event.target.id, userDateOfBirth.value);
});
//Get localStorage
function getLocalStorage() {
const inputs = Array.from(document.querySelectorAll('input'));
inputs.map(input => {
const val = localStorage.getItem(input.id);
return val ? input.value = val : input.value = '';
})
}
getLocalStorage();