Daaka Daaka - 1 month ago 6
Javascript Question

How to prevent defaut behaviour of "input submit"?

I have an input submit, after attaching an onclick handler on it, what's the standard way to prevent a post request to "form action=xxx" url? Is it "return false", or "e.preventDefault", or "e.stopPropogation"?

Answer

just call preventDefault() like this

$("#myform").submit(function(event){
  event.preventDefault();  

  // DO SOMETHING
});