[ciapug] Two dynamic drop downs
Barry Von Ahsen
ciapug@cialug.org
Wed, 27 Oct 2004 16:48:07 -0500
David Champion wrote:
> Chris Hettinger wrote:
>
>> Perhaps someone has a solution to this,
>>
>> In a web form I have two drop downs that I need to build dynamically.
>> The first drop down is a main category and the second drop down box is
>> populated with appropriate options once the first drop down selection
>> has been made.
>>
>> This has to be done with some melding of JavaScript and PHP, but I
>> haven't found the best way to solve this yet.
>>
>> Just curious if anyone else had done something similar and could let
>> me of a good JS script to use or psuedo code of how they solved it.
>>
>
> Barry recently did some javascript voodoo on the iowarealty.com web site
> to do rotating images... the PHP code builds a Javascript array, which
> loops thru the images. You could probably do something similar - load a
> javascript array, and in your onchange for the first control, have it
> load the second one from the array.
>
ah, the joy of mixing client-side scripting with server-side scripting.
the two real options I've used (there may well be others) are either
build the first list, then when a choice is made, resubmit/reload the
page based on that selection. downside: have to reload the page, save
state, form vars, etc, etc.
otherwise, load up the first list, and create every possible second
list, but hide it until the choice is made, then use javascript/dom foo
to show the appropriate second list. downside: many multiple possible
secondary lists, long load time, having all the code in the source
six of one, half-dozen 'tother
-barry