How to Submit a Form Using Jquery?

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


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>





Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.