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

208
Views
is it possible to preventDefault in html?

When i need to prevent default in react , i can put my handler function in onSubmit and everything works fine . <form onSubmit={handler}> . But how do i do the same in pure html ? I need acces to event object as well .

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

try do this :

<form onSubmit="return false;">

about 4 years ago · Juan Pablo Isaza Report

0

You could try something like this.

<form id="form">
    Enter name: <input type="text" name="name">
    <input type="submit" value="Submit">
</form>

<script>
    function onSubmit(event) {
        console.log(event);
        event.preventDefault();
        alert("The form was submitted");
    }

    var form = document.getElementById("form");
    form.onsubmit = onSubmit;
</script>

Reference: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onsubmit

about 4 years ago · Juan Pablo Isaza Report

0

You can do it with jquery library like this:

$(document).on('submit', '#your_form_selector', function(e) {
    e.preventDefault();
    console.log("default submit action was prevented");
}
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!