-1

After submitting, I want to hide my form elemnt from page. I've tried using myForm.style.display == "none" but it doesn't work. Can someone assist me?

let myForm = document.getElementById('contact-form');
  
  myForm.addEventListener('submit', (e) => {
    e.preventDefault();

    const formData = new FormData(myForm);

    fetch('@/api/contact_form_messages', {
      method: 'post',
      body: formData
    })
    .then((checkStatus))
    .then((response) => {
      document.getElementById("success-msg").innerHTML = "Success";
      myForm.style.display == "none";
      return response.text();
    })

Dave
  • 1
  • 1
  • 9
  • 38

1 Answers1

1

You need to assign, not compare, this is incorrect:

myForm.style.display == "none"; // Incorrect

This is correct:

myForm.style.display = "none"; // Correct
Stuart
  • 6,630
  • 2
  • 24
  • 40