Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs: hide-and-seek #22

Open
3 tasks
Tshobohwa opened this issue Feb 11, 2023 · 0 comments
Open
3 tasks

Bugs: hide-and-seek #22

Tshobohwa opened this issue Feb 11, 2023 · 0 comments

Comments

@Tshobohwa
Copy link
Collaborator

Tshobohwa commented Feb 11, 2023

MAKE THE DATA FROM THE LOCAL STORAGE FILL THE FORM INPUTS BY DEFAULT.

whenever the user loads the page, if there is any data relative to the form inputs in the local storage, they should fill in the form inputs.
To solve this issue, proceed as follow.

  • Remove the declaration of the email, fullname, and message from the addFormData function and insert them outside so that they can be accessible in the global scope.
  let email = document.getElementById("email");
  let fullName = document.getElementById("fullname");
  let message = document.getElementById("message");
  • Check if there is any data relative to the form inputs inside the local storage and insert them automatically in the form inputs.
if (localStorage.getItem('contact-data')) {
  const formData = JSON.parse(localStorage.getItem('contact-data'));
  email.value = formData.Email;
  fullName.value = formData.FullName;
  message.value = formData.Message;
}
  • create the addFormData function
const addFormData = () => {
  const form = {
    FullName: fullName.value,
    Email : email.value,
    Message: message.value,
  };
localStorage.setItem('contact-data', JSON.stringify(form))
  console.log(form)
  document.querySelector('form').reset();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant