91Chapter 8Window and Document Objectsdocument.forms[] propertyIt is convenient (Geocities web hosting)

91Chapter 8Window and Document Objectsdocument.forms[] propertyIt is convenient that the document object contains a property document.forms whosevalue is an array of all form element objects in the document. As you recall from thediscussion of arrays in Chapter 7, an index number inside an array s square brackets pointsto one of the elements in the array. To find out how many formobjects are in the currentdocument, usedocument.forms.lengthTo access the first form in a document, for example, the reference isdocument.forms[0] As a further convenience, all scriptable browsers let you reference a form more directly byitsname (that is, the identifier assigned to the nameattribute of the

tag) in one oftwoways. The first way is via array syntax, applying the form s name as a string index valueof the array: document.forms[ formName ] You will see in future chapters that scripts sometimes have only the string name of the formto work with. To derive a valid reference to the formobject indicated by that name, use thisstring index form with the array. The second, even shorter way to reference a formobject by name is to append the name as aproperty of the documentobject, as indocument.formNameEither methodology reaches the same object. You will see many instances of the shortcutapproach in form-related example scripts throughout this book (including in the next chapterwhen working with form controls). Although this syntax dates back to the earliest scriptablebrowsers, it is still valid in the most modern versions. document.images[] propertyJust as a document keeps track of forms in an array property, so does the documentobjectmaintain a collection (array) of images inserted into the document by way of tags. Images referenced through the document.imagesarray may be reached either by numeric orstring index of the imgelement s name. Just like forms, the nameattribute value is the identi- fier you use for a string index. The presence of the document.images property indicates that the browser supports imageswapping. You can therefore use the existence of the property as a controller to make surethe browser supports images as objects before attempting to perform any script action on animage. To do so, surround statements that deal with images with an ifconstruction that veri- fies the property s existence, as follows: if (document.images) { // statements dealing with img objects} Older browsers skip over the nested statements, preventing them from displaying error mes- sages to their users.
Note: If you are looking for high quality webhost to host and run your jsp application check Vision florida web design services