stop button from submit the form HTML

Subject:

if a button if in a form how can you stop it from submitting the form to make an ajx request?

2014-12-21 18:33:34gstlouis

http://stackoverflow.com/questions/932653/how-to-prevent-buttons-from-submitting-forms

This explains to simply add the type='button' and it will prevent this from happening

gstlouis
vote
2014-12-21 18:34:15

event.preventDefault(); // cancel default behavior

gstlouis
vote
2015-02-14 12:06:23

A form has the submit event, not a button. Plus, an ID should be unique so tag#id can just be #id.

$("#theform").submit(function(event) { event.preventDefault(); // ... });

 

references: http://stackoverflow.com/questions/8540395/event-preventdefault-not-working

gstlouis
vote
2015-02-14 12:23:48