Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
Preventing input submit from refreshing page

I would like to prevent my submit button from refreshing my page when I click submit.

This is what I have tried

const formSubmit = e => {
    e.preventDefault();
    const newSubmission = {
      x: horizontal,
      y: vertical,
      steps: count,
      email: email.trim(),
    }
    // console.log(newSubmission)
    postNewSubmission(newSubmission);
  }

and my input:

    <input id="submit" onSubmit={formSubmit} type="submit"></input>

For added context, clicking on submit should send some data to an API and receive some response hence why I am calling postNewSubmission.

To reiterate, the issue is that everytime I click submit it refreshes my page - which is not I what I want - I would like to prevent this default behavior

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Wrap your input in form and put onSubmit on the form

<form onSubmit={formSubmit}>
   <input id="submit" type="submit" value="submit"></input>
</form>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Just put the code below and you are good to go

<script>
if ( window.history.replaceState ) {
  window.history.replaceState( null, null, window.location.href );
}
</script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda