102Part IIJavaScript TutorialListing 9-1:Getting and Setting a Text (Web design seattle)

102Part IIJavaScript TutorialListing 9-1:Getting and Setting a Text Object s value Property

Later in this chapter, I show you how to reduce even further the need for explicit referencesin functions such as upperMe()in Listing 9-1. In the meantime, notice for a moment theonsubmitevent handler in the

tag. I delve more deeply into this event handler laterin this chapter, but I want to point out the construction that prevents a single-field form frombeing submitted when you press the Enter key. If the event handler weren t there, a press ofthe Enter key would reload the page, returning the field to its original text. Try it! The Button ObjectI have used the button-type inputelement in many examples up to this point in the tutorial. The button is one of the simplest objects to script. In the simplified object model of this tuto- rial, the button object has only a few properties that are rarely accessed or modified in day- to-day scripts. Like the text object, the visual aspects of the button are governed not byHTML or scripts, but by the operating system and browser that the page visitor uses. By far, the most useful event handler of the button object is the onclickevent handler. It fires when- ever the user clicks the button. Simple enough. No magic here. The Checkbox ObjectA checkbox is also a simple element of the formobject, but some of the properties may notbe intuitive entirely. Unlike the valueproperty of a plain button object (the text of the buttonlabel), the valueproperty of a checkbox is any other text you want associated with theobject. This text does not appear on the page in any fashion, but the property (initially set viathe valueattribute) might be important to a script that wants to know more about the pur- pose of the checkbox within the form. The key property of a checkbox object is whether or not the box is checked. The checkedproperty is a Boolean value: trueif the box is checked, falseif not. When you see that aproperty is a Boolean value, it s a clue that the value might be usable in an ifor if…elsecondition expression. In Listing 9-2, the value of the checkedproperty determines which alertbox the user sees.

Leave a Reply