jQuery | submit() with Examples

21 Sep, 2018
The submit() method is an inbuilt method in jQuery which is used to submit event or the attaches a function to run when a submit event occurs. This method can only apply on the form elements.Syntax:
$(selector).submit(parameters);
Parameter: The parameters is optional for this method.
Return Value: This method return the selected element along with the attached event.
Program 1: jQuery code to show the working of the submit() method
<html>    <head>        <script src=        "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">        </script>        <script>                      // jQuery code to show the working of this method            $(document).ready(function() {                $("form").submit(function() {                    alert("Form submitted Successfully");                });            });        </script>        <style>            .gfg {                font-size:40px;                color:green;                font-weight:bold;                text-align:center;            }            .geeks {                font-size:17px;                text-align:center;                margin-bottom:20px;            }        </style>    </head>    <body>        <div class = "gfg">GeeksforGeeks</div>        <div class = "geeks">A computer science portal for geeks</div>        <form action = "">        <table border = 1 align = "center">            <tr>                <!-- Enter Username -->                <td>Username:</td>                <td><input type = text name = name size = 25</td>            </tr>            <tr>                <!-- Enter Password. -->                <td>Password:</td>                <td><input type = password name = password1 size = 25</td>            </tr>            <tr>                <!-- To Confirm Password. -->                <td>Confirm Password:</td>                <td><input type = password name = password2 size = 25></td>            </tr>            <tr>                <td colspan = 2 align = right>                <input type = submit value = "Submit"></td>            </tr>        </table>        </form>    </body></html>
Output:
Program 2:
<html>    <head>        <script src=        "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">        </script>        <script>                      // jQuery code to show the working of this method            $(document).ready(function() {                $("form").submit(function() {                    alert("Form submitted Successfully");                });                $("button").click(function() {                    $("form").submit();                });            });        </script>        <style>            .gfg {                font-size:40px;                color:green;                font-weight:bold;                text-align:center;            }            .geeks {                font-size:17px;                text-align:center;                margin-bottom:20px;            }        </style>    </head>    <body>        <div class = "gfg">GeeksforGeeks</div>        <div class = "geeks">A computer science portal for geeks</div>        <form action = "">        <table border = 1 align = "center">            <tr>                <!-- Enter Username -->                <td>Username:</td>                <td><input type = text name = name size = 25</td>            </tr>            <tr>                <!-- Enter Password. -->                <td>Password:</td>                <td><input type = password name = password1 size = 25</td>            </tr>            <tr>                <!-- To Confirm Password. -->                <td>Confirm Password:</td>                <td><input type = password name = password2 size = 25></td>            </tr>            <tr>                <td colspan = 2 align = right>                <button>Click me !</button>            </tr>        </table>        </form>    </body></html>
Output:
JQuery
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Form validation using jQuery
jQuery | children() with Examples
Scroll to the top of the page using JavaScript/jQuery
How to get the value in an input text box using jQuery ?
How to prevent Body from scrolling when a modal is opened using jQuery ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Installation of Node.js on Linux
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?