Re: Two related combo's in ASP



Jerry wrote on Wed, 17 Aug 2005 16:13:30 -0400:

> I have an ASP page that has two combo boxes. In the first is a list of
> Countries. When a user selects a Country, I want the list values within
> the second combo ("State/Province") to dynamically change and reflect the
> states within that Country. I have a table with the various Provinces and
> Countries, but how do I dynamically open a recordset in ASP based on the
> value coming from the first combo? I don't want to redirect the user to
> the same page and pass the country as a requester (ie.
> mypage.asp?country=CAN) because the user will lose any other changes they
> made to the form.

ASP is a server-side scripting technology - therefore the only way you do
this purely in ASP is to submit the entire form, populate the 2nd combo
based on the choice for the first, and send back the entire form again with
all the other bits filled in as they were. It's actually not that hard, and
I've done this myself a number of times.

However, you might find it quicker to use a client side script to do this,
storing all the State/Province data in an array together with the matching
Country code, and then populate the 2nd combo using the onChange() event of
the 1st combo box to build it from the array in the script. This will be
quicker (as there is no round trip back to the server which could introduce
a noticeable delay in the combo population), and also means you don't have
to handle refilling the form with data already entered. However, it does
require that the browser has client side scripting enabled (and if you were
relying on using the onChange() event to fire the request back to the server
to populate the 2nd combo using ASP rather than the user having to click a
button, then the browser will have to have scripting enabled anyway).

Dan


.