Archive for December, 2007

Web hosting comparison - 1306 Part V . Putting JavaScript to Work

Wednesday, December 26th, 2007

1306 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.

1305Chapter 50 .Application: A Lookup Table (Make my own web site) Now comes

Tuesday, December 25th, 2007

1305Chapter 50 .Application: A Lookup Table Now comes the beginning of the data validation functions. Under control of a master validation function shown in a minute, the stripZeros() function removes any leading 0s that the user may have entered. Notice that the instructions tell the user to enter the first three digits of a Social Security number. For 001 through 099, that means the numbers begin with one or two 0s. JavaScript, however, treats any numeric value starting with 0 as an octal value. Because I have to do some numeric comparisons for the search through the ssn[]array, the script must make sure that the entries (which are strings to begin with, coming as they do from text objects) can be converted to decimal numbers. The parseInt() function, with the all-important second parameter indicating Base 10 numbering, does the job. But because the remaining validations assume a string value, the integer is reconverted to a string value before it is returned. // **BEGIN DATA VALIDATION FUNCTIONS** // JavaScript sees numbers with leading zeros as octal values, // so strip zeros function stripZeros(inputStr) { return parseInt(inputStr, 10).toString() } The next three functions are described in full in Chapter 43, which discusses data validation. In the last function, a copy of the input value is converted to an integer to enable the function to make necessary comparisons against the boundaries of acceptable ranges. // general purpose function to see if an input value has been entered // at all function isEmpty(inputStr) { if (inputStr == null || inputStr == ) { return true } return false } // general purpose function to see if a suspected numeric input // is a positive integer function isNumber(inputStr) { for (var i = 0; i < inputStr.length; i++) { var oneChar = inputStr.charAt(i) if (oneChar < 0 || oneChar > 9 ) { return false } } return true } // function to determine if value is in acceptable range for this // application function inRange(inputStr) { num = parseInt(inputStr) if (num < 1 || (num > 586 && num < 596) || (num > 599 && num < 700) || num > 728) { return false } return true }
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

1304 Part V . Putting JavaScript to Work (Web site hosting)

Tuesday, December 25th, 2007

1304 Part V . Putting JavaScript to Work geo[4] = Rhode Island geo[5] = Connecticut geo[6] = New York geo[7] = New Jersey geo[8] = Pennsylvania geo[9] = Maryland geo[10] = Delaware geo[11] = Virginia geo[12] = West Virginia geo[13] = North Carolina geo[14] = South Carolina geo[15] = Georgia geo[16] = Florida geo[17] = Ohio geo[18] = Indiana geo[19] = Illinois geo[20] = Michigan geo[21] = Wisconsin geo[22] = Kentucky geo[23] = Tennessee geo[24] = Alabama geo[25] = Mississippi geo[26] = Arkansas geo[27] = Louisiana geo[28] = Oklahoma geo[29] = Texas geo[30] = Minnesota geo[31] = Iowa geo[32] = Missouri geo[33] = North Dakota geo[34] = South Dakota geo[35] = Nebraska geo[36] = Kansas geo[37] = Montana geo[38] = Idaho geo[39] = Wyoming geo[40] = Colorado geo[41] = New Mexico geo[42] = Arizona geo[43] = Utah geo[44] = Nevada geo[45] = Washington geo[46] = Oregon geo[47] = California geo[48] = Alaska geo[49] = Hawaii geo[50] = District of Columbia geo[51] = Virgin Islands geo[52] = Puerto Rico geo[53] = New Mexico geo[54] = Guam, American Samoa, N. Mariana Isl., Philippines geo[55] = Puerto Rico geo[56] = Long-time or retired railroad workers
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

1303Chapter 50 .Application: A Lookup Table ssn[16] = (Post office web site)

Monday, December 24th, 2007

1303Chapter 50 .Application: A Lookup Table ssn[16] = 267 ssn[17] = 302 ssn[18] = 317 ssn[19] = 361 ssn[20] = 386 ssn[21] = 399 ssn[22] = 407 ssn[23] = 415 ssn[24] = 424 ssn[25] = 428 ssn[26] = 432 ssn[27] = 439 ssn[28] = 448 ssn[29] = 467 ssn[30] = 477 ssn[31] = 485 ssn[32] = 500 ssn[33] = 502 ssn[34] = 504 ssn[35] = 508 ssn[36] = 515 ssn[37] = 517 ssn[38] = 519 ssn[39] = 520 ssn[40] = 524 ssn[41] = 525 ssn[42] = 527 ssn[43] = 529 ssn[44] = 530 ssn[45] = 539 ssn[46] = 544 ssn[47] = 573 ssn[48] = 574 ssn[49] = 576 ssn[50] = 579 ssn[51] = 580 ssn[52] = 584 ssn[53] = 585 ssn[54] = 586 ssn[55] = 599 ssn[56] = 728 I do the same for the array containing the states and territory names. Both of these array populators seem long but pale in comparison to what you would have to do with a database of many kilobytes. Unfortunately, JavaScript doesn t give you the power to load existing data files into arrays (but see the recommendations at the end of the chapter), so any time you want to embed a database into an HTML document, you must go through this array-style assignment frenzy: // create parallel array listing all the states/territories // that correspond to the top range values in the first array var geo = new Array(57) geo[0] = New Hampshire geo[1] = Maine geo[2] = Vermont geo[3] = Massachusetts
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

1302 Part V . Putting JavaScript to Work (Web and email hosting)

Monday, December 24th, 2007

1302 Part V . Putting JavaScript to Work Immediately after the starting tag). Failure to do this results in all code lines appearing in non-JavaScript browsers as regular HTML text. Now we come to the JavaScript 1.1-level scripts, which handle everything from building the tables of data to looking up data later in response to a button click. I begin by creating the first array for the top numbers of each entry s numeric range. In this application, you will see that I place utility function definitions close to the top of the script sections and put any action-oriented scripts (functions acting in response to event handlers) closer to the bottom of the script sections. My preference is to have all dependencies resolved before the script needs them. This philosophy carries over from the logic that dictates putting as many scripts in the Head as possible, so that even if the user (or network) should interrupt downloading of a page before every line of HTML reaches the browser, any user interface element relying on scripts will have those scripts loaded and ready to go. The order of functions in this example is not critical, because as long as they all reside in the Head section, they are defined and loaded by the time the field and button appear at the bottom of the page. But after I develop a style, I find it easier to stick with it one less matter to worry about while scripting a complex application. After creating an array (named ssn) with 57 empty slots, the script populates all 57 data points of the array, starting with the first entry going into the slot numbered 0. These data numbers correspond to the top end of each range in the 57-entry table. For example, any number greater than 3 but less than or equal to 7 falls into the range of the second data entry of the array (ssn[1]).