jQuery > Events

Catch Submit event in jQuery

How to catch the Submit event of the html Form element in jQuery?


To catch the submit event of the html form element, submit() method can be used.

<script>
        $("form").submit(function () {
            $("#divSubmit").fadeIn("fast").text("You have tried to submit the form")
              .delay(500).fadeOut("slow");
            return false;
        });
    </script>

Above code attaches the submit event to the form element and when the form is submitted, it writes “You have tried to submit the form” with fadeout effect (we will learn about fadeout effect in following posts). But note that as the last statement of this function is “return false”, so the form is not be submitted. To submit the form, we must write “return true” in the last.

 Views: 1620 | Post Order: 85



Write for us