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

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

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 Report

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 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!