Web hosting comparison - 1306 Part V . Putting JavaScript to Work
Wednesday, December 26th, 20071306 Part V . Putting JavaScript to Work The master validation controller function (named isValid() in this application) is also covered in depth in Chapter 43. A statement that wants to know if it should proceed with the lookup process calls this function. If any one validation test fails, the function returns false, and the search does not proceed. // Master value validator routine function isValid(inputStr) { if (isEmpty(inputStr)) { alert( Please enter a number into the field before clicking the button. ) return false } else { if (!isNumber(inputStr)) { alert( Please make sure entries are numbers only. ) return false } else { if (!inRange(inputStr)) { alert( Sorry, the number you entered is not part of our database. Try another three-digit number. ) return false } } } return true } // **END DATA VALIDATION FUNCTIONS** The search() function is invoked by two different event handlers (and indirectly by a third). The two direct calls come from the input field s onChangeevent handler and the Search button s onClick event handler. The handler passes a reference to the form, which includes the button and both text objects. To search the database, the script repeatedly compares each succeeding entry of the ssn[] array against the value entered by the user. For this process to work, a little bit of preliminary work is needed. First comes an initialization of a variable, foundMatch, which comes into play later. Initially set to false, the variable is set to true only if there is a successful match information you need later to set the value of the result text object correctly for all possible conditions. // Roll through ssn database to find index; // apply index to geography database function search(form) { var foundMatch = false var inputStr = stripZeros(form.entry.value) if (isValid(inputStr)) { inputValue = inputStr for (var i = 0; i < ssn.length; i++) { if (inputValue <= ssn[i]) { foundMatch = true break } } } form.result.value = (foundMatch) ? geo[i] : form.entry.focus() form.entry.select() }
We recommend high quality webhost to host and run your jsp application: christian web host services.