jQuery .submit() method

Syntax and Description


.submit(handler)         
.submit()

handler is a function to execute each time the event is triggered. Return value is the jQuery object, for chaining purposes.

submit method binds an event handler to the submit JavaScript event, or trigger that event on an element.

.submit(handler) is a shortcut for .bind('submit', handler). .submit() is a shortcut for .trigger('submit').

We can trigger the event manually when another element is clicked.


$('#other').click(function() {
    $('#target').submit();

});

Invoke Submit Event

The following code calls the submit event directly.


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--   w w w . j  av a2 s.c  o m-->
            $("form").submit(function() {
                alert("submit");
                return false;
            });
            $("form:first").submit();
        });
    </script>
  </head>
  <body>
    <body>
    <form action="javascript:alert('success!');">
        <div>
          <input type="text" />
          <input type="submit" />
        </div>
     </form>
     <div></div>
    </body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities