We'll close our discussion of forms with an extended example that
demonstrates several of the concepts we've been talking about.
Example 17.2 shows how you might use the
onSubmit() event handler of the Form object to
perform input validation to notify the user and prevent the form
from being submitted when it contains missing or invalid data.
After studying this example, you may want to turn back to Example 1.3, the forms programming
example with which we began this book. The code of that example
will probably make more sense now that you are a JavaScript
expert!

Example 17.2 defines a
verify() function suitable for use as a
generic form validator. It checks for empty non-optional
fields, and can also check that numeric values are in fact
numeric and that they fall within a specified numeric range.
This verify() function relies on the
type property of form elements to determine
which elements are which, and also relies on additional
user-defined properties to distinguish optional fields from
required fields and to specify the allowed range for numeric
fields. Note also how it reads the value
property of input fields, and uses the name
property of those fields when reporting errors. Figure 17.3 shows an example form
using this verification scheme, and the error message that is
displayed when the user attempts to submit the form before
correctly filling it in.