Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!