166Part IIIDocument Objects ReferenceThe only visible differences to (Web host 4 life)

166Part IIIDocument Objects ReferenceThe only visible differences to the HTML code for defining those objects are the one or moreoptional attributes specifically dedicated to JavaScript. By and large, these attributes specifythe event you want the user interface element to react to and what JavaScript should dowhen the user takes that action. By relying on the document s HTML code to perform theobject generation, you can spend more time figuring out how to do things with those objectsor have them do things for you. Bear in mind that objects are created in their load order. And if you create a multiframe envi- ronment, a script in one frame cannot communicate with another frame s objects until bothframes load. This trips up a lot of scripters who create multiframe and multiwindow sites(more in Chapter 16). Object PropertiesA property generally defines a particular current setting of an object. The setting mayreflect a visible attribute of an object, such as the state of a checkbox (checked or not); itmay also contain information that is not so obvious, such as the action and method of asubmitted form. Document objects have most of their initial properties assigned by the attribute settings ofthe HTML tags that generate the objects. Thus, a property may be a word (for example, aname) or a number (for example, a size). A property can also be an array, such as an arrayof images contained by a document. If the HTML does not include all attributes, thebrowser usually fills in a default value for both the attribute and the correspondingJavaScript property. When used in script statements, property names are case-sensitive. Therefore, if you see aproperty name listed as bgColor, you must use it in a script statement with that exactcombination of lowercase and uppercase letters. But when you set an initial value of aproperty by way of an HTML attribute, the attribute name (like all of HTML) is not case- sensitive. Thus, and both set thesame bgColorproperty value. Although XHTML won t validate correctly if you use any- thing but lowercase letters for tag and attribute names, most browsers continue to becase-insensitive for markup, regardless of the HTML or XHTML version you specify for thepage s DOCTYPE. The case for property names is not influenced by the case of the markupattribute name. Each property determines its own read/write status. Some properties are read-only, whereasyou can change others on the fly by assigning a new value to them. For example, to put somenew text into a text box object, you assign a string to the object s valueproperty: document.forms[0].phone.value = 555-1212 ; Once an object contained by the document exists (that is, its HTML is loaded into the docu- ment), you can also add one or more custom properties to that object. This can be helpful ifyou wish to associate some additional data with an object for later retrieval. To add such aproperty, simply specify it in the same statement that assigns a value to it: document.forms[0].phone.delimiter = - ; Any property you set survives as long as the document remains loaded in the window andscripts do not overwrite the object. Be aware, however, that reloading the page usuallydestroys custom properties.