Home
Form effects
Form to Form Wizard
Form Validation using the oninit and onpagechangestart event handlers
|
Categories
Other Sections
Sweet Ads
Compatibility
|
|
Oninit and onpagechangestart event handlersForm to Form Wizard script supports two event handlers that make it easy,
among other things, to perform validation on each form page as the user goes
from page to page. You can prevent the user from going to another page until the
errors are corrected. If all you need is to validate a form so certain fields
are filled out, you can simply use the built in
validate option to quickly and
easily do that. However, for anything more fancy, the The oninit($, i, $fieldset) event handlerThis event handler is fired once when the script has finished initializing a form and transformed it into a form wizard. This usually happens before the page itself has finished loading. The event is passed three parameters:
The following simple example simply alerts the page number of the current form page when the form wizard loads: <script type="text/javascript"> The onpagechangestart($, i, $fieldset) event handlerThis event handler is fired each time the user is about to go from one form page to another, such as when the user has filled out the first page and clicks "next”" to proceed to the 2nd. This is the primary event handler you'll be using to perform custom validation on each form page. The event is also passed three parameters:
By returning false from this event handler, you disable the user's ability to go on to the next page until a value of true is returned. The following example checks each page's INPUT type="text" and TEXTAREA elements to ensure they aren't blank before letting the user proceed on to the next page:
The var $els=$fieldset.find('input[type="text"], textarea')
references both textbox and textarea elements that may be on the visible
form page. The code that follows checks to see if any of these elements (if
present) are empty, and if so, empty the loop and sets If you're not comfortable working with jQuery selectors, you can always use the DOM instead, by referring to $fieldset.get(0) instead of $fieldset. The below accomplishes the same validation as the above example, but using the DOM syntax instead:
Table Of Contents
|