.submit()

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 a  v  a  2  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

The code above generates the following result.

.submit()
Home »
  Javascript Tutorial »
    jQuery Reference »
      Event
Javascript Tutorial Event
Event
Event attributes
event.keycode
event.clientX/clientY
pageX/pageY
Cancel event
Event target
bind
.blur()
.change()
.click()
.error()
.dblclick()
.delegate()
.die()
.focus()
.hover()
.keydown()
.keypress()
.keyup()
.live()
.load()
.mousedown()
.mouseenter()
.mouseleave()
.mousemove()
.mouseover()
.mouseout()
.mouseup()
.off()
.on()
.one()
.ready()
.resize()
.scroll()
.select()
.submit()
.toggle()
.trigger()
.triggerHandler()
.unbind()
.undelegate()
.unload()