From 497ee05830624a418b0c761a9ae746f6fb83858a Mon Sep 17 00:00:00 2001 From: TetiZ Date: Thu, 1 Feb 2024 09:09:34 +0100 Subject: [PATCH] submit email corrects --- src/js/submit-email-footer.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/js/submit-email-footer.js b/src/js/submit-email-footer.js index d661973..19f5707 100644 --- a/src/js/submit-email-footer.js +++ b/src/js/submit-email-footer.js @@ -4,20 +4,16 @@ import 'izitoast/dist/css/iziToast.min.css'; const form = document.querySelector('.subs-form'); const localStorageKey = 'user-email'; -const savedEmail = localStorage.getItem(localStorageKey); - -if (savedEmail) { - form.elements.email.value = savedEmail; -} else { - form.elements.email.value = ''; -} - form.addEventListener('input', saveToLocalStorage); function saveToLocalStorage(evt) { localStorage.setItem(localStorageKey, evt.target.value); } +const savedEmail = localStorage.getItem(localStorageKey); + +form.elements.email.value = savedEmail ? savedEmail : ''; + async function postEmail(userEmail) { try { const response = await fetch(