submit() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:submit

Description

The submit() method triggers the submit event, or sets function as submit event handler.

Syntax

Parameter Require Description
function Optional.function to run when the submit event is triggered

The following code shows how to Display an alert when a form is submitted:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("form").submit(function(){
        console.log("Submitted");
    });//from  www . j  a  v a2s. c  om
});
</script>
</head>
<body>

<form action="">
  First name: <input type="text" name="FirstName" value="Bond"><br>
  Last name: <input type="text" name="LastName" value="Mary"><br>
  <input type="submit" value="Submit">
</form>

</body>
</html>

Related Tutorials