I'm using the HTML5 form tag for the client side validator built into it, but I don't want it to submit a thing as I've just got a Javascript function to run instead.
How can i stop the Post method of the form.
Cheers - Caius
Use the preventDefault() method on the event object to prevent a page refresh on form submit in React, e.g. event. preventDefault() . The preventDefault method prevents the browser from issuing the default action which in the case of a form submission is to refresh the page.
The simplest solution to prevent the form submission is to return false on submit event handler defined using the onsubmit property in the HTML <form> element.
We use the preventDefault() method with this event to prevent the default action of the form, that is prevent the form from submitting. Example: HTML.
add a return false after the function call, like so:
<input .... onclick="function();return false;" />
or you could just return true/false from the function like so:
<input .... onclick="return function()" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With