JQuery: onsubmit event example

This page uses JQuery to handle onsubmit events. When you submit the form below, an alert box pops up.

If you recall, in a previous example, we used the "onsubmit" attribute of <form> tag to detect the onsubmit events without JQuery.

This technique using JQuery is better because it does not require any changes to the XHTML code - all the behaviors are coded in Javascript, which means the code responsible for behaviors is clearly separated from the markup code. Plus, the syntax is more standardized than the default Javascript way of doing things in Javascript, which is usually totally inconsistent.