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

94
Visualizações
Prevent form from submitting with certain buttons HTML/JS

I am working on a school website, where you can make an assignment. I have a submit button, which is the one that should redirect. I also have some other buttons within this form which are not submit buttons. The problem is, When i click those buttons that i don't want to redirect, it still redirects. What i thought i should do is:

form.addEventListener("submit", (e) =>{
     e.preventDefault();
}

But have realised that that would stop me from submitting at all.

I am not sure what to do. I have tried event.preventDefault for each button, but that doesn seem to work either.

How do i fix this please help I need answers pronto!

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

0

The HTML buttons can be of three types:

button  The button is a clickable button
submit  The button is a submit button (submits form-data)
reset   The button is a reset button (resets the form-data to its initial values)

You might want to try setting the type of the button to clickable and have just the one submit button.

Hopefully that helps you.

Reference:

  • https://www.w3schools.com/tags/att_button_type.asp
about 4 years ago · Juan Pablo Isaza Relatório

0

You can set the button type to 'button' instead of 'submit', but if you insist on using submit you can also use this function to prevent the page from reloading after submitting the form.

<form onsubmit="handleSubmit()">
  Type Something: <input type="text" name="example">
  <input type="submit" value="Submit">
</form>

<script>
  function handleSubmit(e) {
     e.preventDefault();
  }
</script>
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