F
F
Froggyweb2021-07-04 13:43:15
JavaScript
Froggyweb, 2021-07-04 13:43:15

Reset does not work on the form?

After the condition in the if condition is met, the form reset does not work. In the ife, the form code with errors is substituted, but e.target seems to be new. Why reset does not work after fixing errors is not clear.

document.addEventListener("submit", function (e) {
  const form = e.target;
  if (true) {
    document.querySelector('.form-wrap').innerHTML = "Новая форма"
  }
  fetch("/" + formname, {
    method: "post",
    body: new FormData(form),
  })
    .then((res) => res.json())
    .then((res) => {
      if (res.status) {
        form.reset;
      }
    })
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-07-04
@Seasle

- form.reset;
+ form.reset();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question