jQuery submit() Method

Last Updated:

jQuery submit() Method

The jQuery submit() method is used for the following 2 purpose

  1. To run a callback when a form is submitted.
  2. To trigger the submit event of a form.

Run a Callback

In the following example, we will run a callback function when a form is submitted.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery submit() Method</h1> <form action="/user-name.php"> Name: <input type="text" name="name"> <button type="submit">Submit</button> </form> <script> $(document).ready(function(){ $("form").submit(function(){ alert("Your form is submitted"); }); }); </script> </body> </html>

Syntax

// Trigger the submit event $(selector).submit(); // Attach a callback to submit event $(selector).submit(callback);

Parameter Values

Value Type Explanation
callback Optional Specifies the function to run when the submit event is triggered.

Browser Support

Devicedesktopmobile
Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet
submit()YesYesYesYesYesYesYesYesYesYesYesYesYes

Trigger a submit Event

In the following example, we will trigger a submit event when a paragraph is clicked.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery submit() Method</h1> <form action="/user-name.php"> Name: <input type="text" name="name"> <button type="submit">Submit</button> </form> <p>Click on this paragraph to submit the form</p> <script> $(document).ready(function(){ $("p").click(function(){ $("form").submit(); }); }); </script> </body> </html>

Share this Page

Meet the Author