Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
How to avoid the user from repeating to fill in the form if there is an error?

Problem: I'm doing a form to be filled by the user. Once the user clicks submit, if there is an error in the form, it will show an alert. However, when the user clicks "ok" the form will reset all the fields that have been filled so the user needs to repeat in fill in the form all over again.

Question: How to fix this so that when the user clicks "ok" the data is still there?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

To stop the page from re-loading add return false; after alert statement, it stops the default action from taking place from the form submit.

alert("Please fill in all mandatory fields");
return false;
about 4 years ago · Juan Pablo Isaza Relatório

0

You should reset form:

document.getElementById("formId").reset();
about 4 years ago · Juan Pablo Isaza Relatório

0

The <button> element, when placed in a form, will submit the form automatically unless otherwise specified. You can use the following 2 strategies:

  • Use <button type="button"> to override default submission behavior.
  • Use event.preventDefault() in the onSubmit event to prevent form submission.
var form = document.getElementById("myForm");
function handleForm(event) { event.preventDefault(); } 
form.addEventListener('onSubmit', handleForm);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda