To facilitate client-side validation, a validation function is defined for each form, and a pointer to each function is placed in an array that parallels the form array (you don't have to defined a form array, HTML does that for you. So you'll have something like this:
true ); }var maxform = document.forms.length;
var validation_functions = new Array( maxform );validation_functions[ 1 ] = validate_form1;
validation_functions[ 2 ] = validate_form2;
validation_functions[ 3 ] = validate_form3;
validation_functions[ 4 ] = validate_form4;function validate_form1() { /* do validation */ return ( true ); }
function validate_form2() { /* do validation */ return (
This enables the next() function, called when the user clicks the next or submit button, to index into the validate_functions array and call the appropriate function. If the validation function returns true, the next function proceeds to the next form. If it returns false, it returns the user to the current form.
You must provide a validation function for every form.
Yes
The next() and previous() functions are invoked in response to the user selecting the next and previous buttons. They are quite simple, but they are really the heart of the implementation. So maybe they're worth looking at in detail.
First, previous() simply sets the boolean flag prev to true, then it invokes next().
next();function previous()
{prev = true;
}
Read Slate
Subscribe but don't read
Time
Read whatchamicallit
Function next() first sets the current form display property to none. Then if the prev is true, it decrements fnum, the global form counter. Otherwise, all indications are that the user intends to proceed to the next form, so it's necessary to invoke the validation function for the current form. If the validation fnction returns false, next() returns the display property to normal, thereby restoring visibility. If the validation function returns true, next() performs a sanity check to ensure that fnum is within range and then increments fnum. Lastly, next() sets the display property for the current form, as defined by fnum, to normal.
--fnum;function next()
{document.forms[fnum].style.display = "none";
if ( prev == true && fnum >= 1 ) {
document.forms[fnum].style.display = "";
}
Last but not least, there is the submit function. As implemented here, submit simply summarizes your input in the browser window, sort of like this:
var str = 'function SubmitIt()
{
var i, j;
document.forms[fnum].style.display = "none";
for ( i=0; i < maxform; i++ ) {