jQuery submit() Method

You are Here:

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

ValueTypeExplanation
callbackOptionalSpecifies the function to run when the submit event is triggered.

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>

Reminder

Hi Developers, we almost covered 99.5% of jQuery Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in jQuery.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author