jQuery submit()

Introduction

Display an alert when a form is submitted:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/* ww w .j a v a2 s  .c om*/
<script>
$(document).ready(function(){
  $("form").submit(function(){
    document.getElementById("demo").innerHTML = "Submitted";
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<form action="">
  First name: <input type="text" name="FirstName" value="CSS"><br>
  Last name: <input type="text" name="LastName" value="HTML"><br>
  <input type="submit" value="Submit">
</form>

</body>
</html>

The submit event occurs when a form is submitted.

This event can only be used on <form> elements.

The submit() method triggers the submit event.

P:The submit() method can also run a function when a submit event occurs.

Trigger the submit event for the selected elements:

$(selector).submit()

Attach a function to the submit event:

$(selector).submit(function)
Parameter Optional Description
function Optional. function to run when the submit event is triggered



PreviousNext

Related