Archive for July, 2007

Free php web host - 995Chapter 37 .The Array Object Multidimensional Arrays An

Friday, July 27th, 2007

995Chapter 37 .The Array Object Multidimensional Arrays An alternate to parallel arrays is the simulation of a multidimensional array. While it s true that JavaScript arrays are one-dimensional, you can create a one- dimensional array of other arrays or objects. A logical approach is to make an array of custom objects, because the objects easily allow for naming of object properties, making references to multidimensional array data more readable (custom objects are discussed at length in Chapter 41). Using the same data from the examples of parallel arrays, the following statements define an object constructor for each data record. A new object is then assigned to each of four entries in the main array. // custom object constructor function officeRecord(city, manager, quota) { this.city = city this.manager = manager this.quota = quota } // create new main array var regionalOffices = new Array() // stuff main array entries with objects regionalOffices[0] = new officeRecord( New York , Shirley Smith , 300000) regionalOffices[1] = new officeRecord( Chicago , Todd Gaston , 250000) regionalOffices[2] = new officeRecord( Houston , Leslie Jones , 350000) regionalOffices[3] = new officeRecord( Portland , Harold Zoot , 225000) The object constructor function (officeRecord()) assigns incoming parameter values to properties of the object. Therefore, to access one of the data points in the array, you use both array notations to get to the desired entry in the array and the name of the property for that entry s object: var eastOfficeManager = regionalOffices[0].manager You can also assign string index values for this kind of array, as in regionalOffices[ east ] = new officeRecord( New York , Shirley Smith , 300000) and access the data via the same index: var eastOfficeManager = regionalOffices[ east ].manager But if you re more comfortable with the traditional multidimensional array (from your experience in other programming languages), you can also implement the above as an array of arrays with less code: // create new main array var regionalOffices = new Array() // stuff main array entries with arrays regionalOffices[0] = new Array( New York , Shirley Smith , 300000) regionalOffices[1] = new Array( Chicago , Todd Gaston , 250000) regionalOffices[2] = new Array( Houston , Leslie Jones , 350000) regionalOffices[3] = new Array( Portland , Harold Zoot , 225000)
We recommend high quality webhost to host and run your jsp application: christian web host services.

994 Part IV . JavaScript (Web hosting e commerce) Core Language Reference

Thursday, July 26th, 2007

994 Part IV . JavaScript Core Language Reference Listing 37-4 (continued) var regionalOffices = new Array( New York , Chicago , Houston , Portland ) var regionalManagers = new Array( Shirley Smith , Todd Gaston , Leslie Jones , Harold Zoot ) var regOfficeQuotas = new Array(300000, 250000, 350000, 225000) // do the lookup into parallel arrays function getData(form) { // make a copy of the text box contents var inputText = form.officeInp.value // loop through all entries of regionalOffices array for (var i = 0; i < regionalOffices.length; i++) { // compare uppercase versions of entered text against one entry // of regionalOffices if (inputText.toUpperCase() == regionalOffices[i].toUpperCase()) { // if they re the same, then break out of the for loop break } } // make sure the i counter hasn t exceeded the max index value if (i < regionalOffices.length) { // display corresponding entries from parallel arrays form.manager.value = regionalManagers[i] form.quota.value = regOfficeQuotas[i] } else { // loop went all the way with no matches // empty any previous values form.manager.value = form.quota.value = // advise user alert( No match found for + inputText + . ) } }

Parallel Array Lookup II


Enter a regional office:

The manager is:
The office quota is:


Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Web server logs - 993Chapter 37 .The Array Object } Parallel Array

Thursday, July 26th, 2007

993Chapter 37 .The Array Object }

Parallel Array Lookup


Select a regional office:

The manager is:
The office quota is:

On the other hand, if the content to be looked up is typed into a text box by the user, you have to loop through one of the arrays to get the matching index. Listing 37-4 is a variation of Listing 37-3, but instead of the SELECT element, a text field asks users to type in the name of the region. Assuming that users will always spell the input correctly (an outrageous assumption), the version of getData() in Listing 37-4 performs actions that more closely resemble what you may think a lookup should be doing: looking for a match in one array, and displaying corresponding results from the parallel arrays. The for loop iterates through items in the regionalOfficesarray. An ifcondition compares all uppercase versions of both the input and each array entry. If there is a match, the forloop breaks, with the value of istill pointing to the matching index value. Outside the for loop, another if condition makes sure that the index value has not reached the length of the array, which means that no match is found. Only when the value of i points to one of the array entries does the script retrieve corresponding entries from the other two arrays. Listing 37-4: A Looping Array Lookup Parallel Array Lookup II
Please enter your birthdate…
Month: Date: Year:

Thank you for entering:

The page shows the three entry fields as well as a field that is normally hidden on a form to be submitted to a CGI program. On the server end, the CGI program responds only to the hidden field with the complete date, which is in a format for entry into, for example, an Informix database. Not every date entry validation must be divided in this way. For example, an intranet application can be more demanding in the way users are to enter data. Therefore, you can have a single field for date entry, but the parsing required for such a validation is quite different from that shown in Listing 36-5. See Chapter 43 for an example of such a one-field date validation routine. …
You want to have a cheap webhost for your apache application, then check apache web hosting services.