Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop a HTML5 form posting, refreshing or opening a new window onSubmit

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

like image 768
Caius Eugene Avatar asked Jan 06 '12 10:01

Caius Eugene


People also ask

How do I stop form from refreshing after submitting HTML?

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.

How do I stop Onsubmit?

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.

How do I stop form action in HTML?

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.


1 Answers

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()" />
like image 171
Tom Avatar answered Oct 05 '22 11:10

Tom