jQuery submit() with Examples


The submit() method in jQuery is used to trigger the submit event. It occurs when a form is submitted.

Syntax

The syntax is as follows −

$(selector).submit(func)

Above, the func parameter is the function to run when the submit event is triggered

Example

Let us now see an example to implement the jQuery submit() method −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function() {
      $("form").submit(function(){
         alert("Form Submitted");
      });
   });
</script>
</head>
<body>
<h2>Login<h2>
<form action="">
Enter Username:
<input type="text"><br>
Enter Password:
<input type="password"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Output

This will produce the following output−

Click the “Submit” button −

Updated on: 30-Dec-2019

329 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements