Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 24. Client-Side Input Validation > Using the Validation Functions

Using the Validation Functions

This section does not provide a tip, but rather offers an example of how to use the validation functions in a form. Listing 24.17 is an HTML page with a form containing three input elements: Company, ProductID, and ProductQuantity. As you may have guessed, this form enables customers to order products. The Company, ProductID, and ProductQuantity boxes must not be left empty. In addition, ProductQuantity can contain only a number. Note that the HTML page includes a <SCRIPT> section with three functions: trim, isPositiveInteger, and validateForm. The validateForm function is assigned as the handler for the form’s onSubmit event. It is called just before the form is submitted. The validateForm function will return true only if the three boxes have valid values. If the validateForm function returns false, the form is not submitted. If one of the three form elements has an invalid value, an alert box is issued and the focus shifts to the box whose value is invalid.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint