1167Chapter 43 .Data-Entry Validation } (Cool web site) gField.value = inputStr

1167Chapter 43 .Data-Entry Validation } gField.value = inputStr var expandField = window.frames[gFrame.name].document.forms[0].elements[gField.name + _expand ] expandField.value = USStates[inputStr] return true } The function assumes that the user tried to enter a valid state abbreviation but either had incorrect source material or momentarily forgot a particular state s abbreviation. Therefore, the function examines the first letter of the entry. If that first letter is any one of the five identified as causing the most difficulty, a legend for all states beginning with that letter is assigned to the msgvariable (for running on newer browsers only, a switchconstruction is preferred). An alert message displays the generic alert, plus any special legend if one is assigned to the msgvariable. When the user closes the alert, the field has focus and its text is selected. (This application runs solely on Navigator, so the IE setTimeout() workaround isn t needed but you can add it very easily, especially thanks to the global variable reference for the field.) The function returns false at this point. If, on the other hand, the abbreviation entry is a valid one, the field is handed the uppercase version of the entry. The script then uses the two global variables set in validate() to create a reference to the expanded display field (whose name must be the same as the entry field plus _expand ). That expanded display field is then supplied the USStates array entry value corresponding to the abbreviation label. All is well with this validation, so it returns true. You can see here that the so-called validation routine is doing far more than simply checking validity of the data. By communicating with the field, converting its contents to uppercase, and talking to another field in the form, a simple call to the validation function yields a lot of mileage. Date validation Many of the forms in this application have date fields. In fact, dates are an important part of the data maintained in the database behind the forms. All users of this application are familiar with standard date formats in use in the United States, so I don t have to worry about the possibility of cultural variations in date formats. Even so, I want the date entry to accommodate the common date formats, such as mmddyyyy, mm/dd/yyyy, and mm-dd-yyyy (as well as accommodate two-digit year entries spanning 1930 to 2029). The plan also calls for going further in helping users enter dates within certain ranges. For example, a field used for a birth date (the listings are for medical professionals) should recommend dates starting no more than 90 years, and no less than 20 years, from the current date. And to keep this application running well into the future, the ranges should be on a sliding scale from the current year, no matter when it might be. Whatever the case, the date range validation is only a recommendation and not a transaction stopper. Rather than create separate validation functions for each date field, I create a system of reusable validation functions for each date range (several fields on different forms require the same date ranges). Each one of these individual functions calls a single, generic date-validation function that handles the date-range checking. Listing 43-13 shows a few examples of these individual range-checking functions.
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Leave a Reply