Scripting Select Boxes with ASP
By Alan Smithy
Most Web sites use at least one set of isolated, normalized data, and possibly dozens of sets. A set can be any list of infrequently changing datalists of states, countries, vendors, colors, sizes, or shapes.
Whatever the actual data may be, its existence (perhaps in a database) and its appearance (probably as a list boxa.k.a. a SELECT boxon a Web page) bear two advantages. First, isolated, normalized data helps your site's visitors by offering a finite set of options. Selecting a state from a list is better than guessing at the two-letter abbreviation. If you had a text box on your Web page instead of a SELECT box, the input you'd receive from your visitors would vary wildly. When you ask for a state, one person might enter "California," another might write in "CA," and a third person might write "Ca." But when your visitors are choosing from such a list, your data remains normal, or standardizedthe second advantage.
This article will focus on methods for populating and managing such SELECT boxes. We'll demonstrate with some basic examples and then progress into optimized, highly functional SELECT box codelets that use various methods to fill and manage both static and dynamic SELECT box controls.
The ASP script in
Listing 1 generates a simple data-driven SELECT box. It displays a list of publishers that it pulls from a simple database table. Using such a mechanismthat is, displaying a pull-down list of publishers from which the user must make one selectionguarantees that data from the user is valid.