Java Reference
In-Depth Information
Next in your look at elements were the drop-down list and list boxes. Both, in fact, are the same
select element, with the size attribute determining whether it's a drop-down or list box. The
<select> tag creates these elements, the size attribute determining how many list items are
visible at once. If a size of 1 is given, a drop-down box rather than a list box is created. Each
item in a select element is defi ned by the <option/> element, or added to later by means of
the Select object's options collection property, which is an array-like structure containing
each Option object for that element. However, adding options after the page is loaded differs
slightly between IE7 and other browsers. The Select object's selectedIndex property tells
you which option is selected; you can then use that value to access the appropriate option in the
options collection and use the Option object's value property. The Option object also has the
text and index properties, text being the displayed text in the list and index being its position
in the Select object's options collection property. You can loop through the options collec-
tion, fi nding out its length from the Select object's length property. The Select object has
the change event, which fi res when the user selects another item from the list.
In the next chapter, you'll look at how, once you have created a frameset in a page, you can access code
and variables between frames. You'll also look at how to open new windows using JavaScript, and
methods of manipulating them when they are open. You'll see the trivia quiz become a frame-based
application.
Exercise Questions
Suggested solutions to these questions can be found in Appendix A.
1.
Using the code from the temperature converter example you saw in Chapter 2, create a user
interface for it and connect it to the existing code so that the user can enter a value in degrees
Fahrenheit and convert it to centigrade.
2.
Create a user interface that allows the user to pick the computer system of their dreams, simi-
lar in principle to the e-commerce sites selling computers over the Internet. For example, they
could be given a choice of processor type, speed, memory, and hard drive size, and the option
to add additional components like a DVD-ROM drive, a sound card, and so on. As the user
changes their selections, the price of the system should update automatically and notify them
of the cost of the system as they specifi ed it, either by using an alert box or by updating the con-
tents of a text box.
Search WWH ::




Custom Search