To read the article online, visit http://www.4GuysFromRolla.com/webtech/061399-1.shtml

Multiple, Dynamic Drop-Down Boxes


This question was asked on the ASP Newbie ListServ not long ago:

Can anyone point me to a site where I can find an example, with code, of dynamic drop-down boxes? For example, if you choose an item in the first box, the selections change in the second one?

An answer was skillfully fielded by Bill Wilkinson, a member of the ChiliSoft team. Here's what Bill had to say:

Basically, there are two ways to do this:

1.) Send EVERYTHING needed to the page in one fell swoop. That is, send ALL the possible "second box" choices to the page and keep them in a JavaScript array. Then when the choice is made in the first box, use JavaScript to pick out the right pieces of the array and populate the second list.

ADVANTAGE: Simple to understand, once you understand client side JavaScript coding. Doesn't need ASP, really. Just put it all in your HTML code and you are done.

DISADVANTAGE: Depending on how many choices, IN ALL, you have, it could be REAL slow to send that page from the server to the browser. I mean REAL slow if we are talking thousands of choices, in all.


2.) When the user makes a selection in the first list, THEN go back to the server and get the data for the second list. There are two ways to do this:

(a) The "pure" ASP way. Basically, you ask ASP to send a complete replacement for the current page.

ADVANTAGE: Simplest of all to code! Once you understand making DB queries via ADODB and ASP, this is truly trivial code.

(b) The "heterogeneous" way. Using either a browser-side ActiveX control or a browser-side Java Applet, you send a request back to the server for the needed info and fill in the second box "in place".

ADVANTAGE: I'm trying to think of one. Oh, yeah: if you use Visual Interdev 6, you can use a "Design Time Control" and do almost no coding.

DISADVANTAGE: Complex. Hard to understand what is REALLY going on. Well, if you are a Java person, maybe the Java solution isn't really hard, but at best we are talking learning how to use JDBC.

DISADVANTAGE: You can NOT use a standard HTML <SELECT> drop down list. (Well, with Java you *could*, by communicating between Java and JavaScript...but that's more complex than even a pure Java solution.)

DISADVANTAGE for (2.a) AND (2.b): An extra round trip to the server for each new "box 2" drop down list.


Personally, I would say that on all but the busiest sites solution (2.a) is the way to go. It is SO much simpler and cleaner than the others. But it can be a performance hit. If the total number of drop down items isn't too high (low hundreds?), probably (1) offers the best performance for busy sites, esp. if the HTML page is "pre built" instead of having to be created from a database each time.

Whew. No detailed solutions, but I hope some food for thought.


Bill Wilkinson
Chili!Soft: http://www.chilisoft.com
"Pioneering Cross-Platform Active Server Pages"


Article Information
Article Title: Multiple, Dynamic Drop-Down Boxes
Article Author: Bill Wilkinson
Published Date: Sunday, June 13, 1999
Article URL: http://www.4GuysFromRolla.com/webtech/061399-1.shtml


Copyright 2017 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers