How to Submit a Form Using Jquery?
Here we shall discuss how we are going to submit the form from a jquery program. Earlier, we had discussed how to submit a program using javascript. Now, we shall discuss how to submit a program using Jquery.
Like javascript that provides the submit() method, we have a submit method in Jquery as well.
Jquery Submit() method Example
$('#formid').submit(function() { alert('I am submitted'); return false; });
In the code above, formid is the id of the form and we are attaching the submit() method to it.
The complete code would look like this:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="container">
<form action="submit.php">
<div>
<input type="submit" />
</div>
</form>
<span></span>
<script>
$("form").submit(function() {
alert("This is a submit");
return false;
});
</script>
</div>
</body>
</html>