In my case, all forms are submitted using the javascript submit () method
In this case, you can wrap this method. This is important because when you call the DOM method HTMLFormElement#submit , submit event handlers are not . (If you use the jQuery submit method instead, it starts the handlers before submitting the form.)
Here's how you wrap this function without using any libraries:
Array.prototype.forEach.call(document.querySelectorAll("form"), function(form) { var realSubmit = form.submit; form.submit = function() {
... or as you noted your jquery question using jQuery:
$("form").each(function() { var form = this; var realSubmit = form.submit; form.submit = function() {
You need to check if your target browsers are allowed. Modern.
Here is a complete example: Live Copy
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> <meta charset="utf-8"> <title>Example</title> </head> <body> <p>This page adds the q field to a form it submits to Google</p> <form method="GET" action="http://google.com/search" target="_blank"> <input id="sendDOM" type="button" value="Send with DOM submit"> <input id="sendjQuery" type="button" value="Send with jQuery submit"> </form> <script> $("#sendDOM").click(function() { $("form")[0].submit(); }); $("#sendjQuery").click(function() { $("form").submit(); }); </script> </body> </html>
source share