80Part IIJavaScript Tutorialis found. When the forloop breaks, (Hosting your own web site)

80Part IIJavaScript Tutorialis found. When the forloop breaks, the value of the icounter is fixed at the row of theUSStatesarray containing the entered state. I need that index value to find the correspond- ing entry in the other array. Even though the counting variable, i, is initialized in the forloop, it is still alive and in the scope of the function for all statements after the initialization. That s why I can use it to extract the value of the row of the stateEnteredarray in the finalstatement that displays the results in an alert message. This application of a forloop and array indexes is a common one in JavaScript. Study thecode carefully and be sure you understand how it works. This way of cycling through arraysplays a role not only in the kinds of arrays you create in your code, but also with the arraysthat browsers generate for the document object model. Document objects in arraysIf you look at the documentobject portions of the Quick Reference in Appendix A, you cansee that the properties of some objects are listed with square brackets after them. These are, indeed, the same kind of square brackets you just saw for array indexes. That s because whena document loads, the browser creates arrays of like objects in the document. For example, ifyour page includes two

tag sets, then two forms appear in the document. Thebrowser maintains an array of form objects for that document. References to those forms aredocument.forms[0] document.forms[1] Index values for document objects are assigned according to the loading order of the objects. In the case of formobjects, the order is dictated by the order of the
tags in the docu- ment. This indexed array syntax is another way to reference forms in an object reference. Youcan still use a form s identifier if you prefer and I heartily recommend using object nameswherever possible because even if you change the physical order of the objects in yourHTML, references that use names still work without modification. But if your page containsonly one form, you can use the reference types interchangeably, as in the following examplesof equivalent references to the length property of a form s elementsarray (the elementsarray contains all the form controls in the form): document.getElementById( entryForm ).elements.lengthdocument.forms[0].elements.lengthIn examples throughout this book, you can see that I often use the array type of reference tosimple forms in simple documents. But in my production pages, I almost always use namedreferences. Exercises1.With your newly acquired knowledge of functions, event handlers, and control struc- tures, use the script fragments from this chapter to complete the page that has thelookup table for all of the states and the years they entered into the Union. If you donot have a reference book for the dates, use different year numbers starting with 1800for each entry. In the page, create a text entry field for the state and a button that trig- gers the lookup in the arrays.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services