JavaScript: Stop post or get method from being processed by a submit input type

From The Travis van der Font Wiki
Jump to: navigation, search
Use an HTML5 button element instead of Input type 'submit'.
<button type="button" id="submit_btn">Submit</button>
Using jQuery:
$(function() // execute once the DOM has loaded
   // example from click submission event
   $('#submit_btn').click(function (event)
      event.preventDefault(); // cancel default behavior

      // ...
      return false;

   // example from form submission event
   $("form").submit(function (event)
      event.preventDefault(); // cancel default behavior

      // ....
or using pure JavaScript:
document.querySelector("#submit_btn").addEventListener('click', function(event)

Submitting from an onclick button is also possible.

<button onclick="return exampleFunc(this)" type="submit">Submit</button>
function exampleFunc(event)
   // document.getElementById("myForm").submit();
   return false; // return true;

Applying an onsubmit attribute to return false on the parent (current) <form> with an empty method will also stop a form from being submitted, as such:
<form method="#" onsubmit="return false;">

Additional Reference(s)