Web site development - 1166 Part V . Putting JavaScript to Work
1166 Part V . Putting JavaScript to Work Listing 43-11 (continued) USStates[ SD ] = SOUTH DAKOTA USStates[ TN ] = TENNESSEE USStates[ TX ] = TEXAS USStates[ UT ] = UTAH USStates[ VT ] = VERMONT USStates[ VA ] = VIRGINIA USStates[ WA ] = WASHINGTON USStates[ WV ] = WEST VIRGINIA USStates[ WI ] = WISCONSIN USStates[ WY ] = WYOMING The existence of this array comes in handy in determining if the user enters a valid, two-state abbreviation. Listing 43-12 shows the actual isUSState() validation function that puts this array to work. The function s first task is to assign an uppercase version of the entered value to a local variable (inputStr), which is the value being analyzed throughout the rest of the function. If the user enters something in the field (length > 0) but no entry in the USStatesarray exists for that value, the entry is not a valid state abbreviation. Time to go to work to help out the user. Listing 43-12: Validation Function for U.S. States // input value is a U.S. state abbreviation; set entered value to all uppercase // also set companion field (NAME=
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.