Link to home
Start Free TrialLog in
Avatar of Michael Vasilevsky
Michael VasilevskyFlag for United States of America

asked on

Creating Cascading Combo boxes in ASP

I'd like to create "cascading" combo boxes on a webpage with ASP using VBScript.  By cascading I mean the second combo box depends on the value selected in the first, and the third combo box depends on the value selected in the second.  I connect to a Access 2002 database with ADO to populate the combo boxes.  The thing is, I'd like to do it without reloading the page each time a value is selected.  What's the easy way to do this?
Any help would be appreciated.
Thanks,

mv
ASKER CERTIFIED SOLUTION
Avatar of Silversoft
Silversoft

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michael Vasilevsky

ASKER

That looks nice.  I don't know any javascript, so how would you populate the array with database values?  Also why:

lists['USA'][0] = new Array(
     'New York',
     'Los Angeles'
);
lists['USA'][1] = new Array(
     'New York',
     'Los Angeles'
);
?
Seems redundant to have to state the values twice.  
Finally, is there no vbscript solution?
Thanks,

mv
Avatar of mrwebdev
mrwebdev

Nice... Good Advice  SilverSoft!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry forgot to comment, one array is the actula display text and the other is the value of the combo box.
Regarding VBscript, I wouldnt recommend VBscript as a client language as it only compatible with MS IE and none of the others, Javascript is more standard and more compatible.

*****************************************************************

// First set of text and values
lists['Australia']    = new Array();
//TEXT ARRAY
lists['Australia'][0] = new Array(
     'Sydney',
     'Brisbane'
);
//VALUE ARRAY
lists['Australia'][1] = new Array(
     'Sydney',
     'Brisbane'
);

// Second set of text and values
lists['USA']    = new Array();
//TEXT ARRAY
lists['USA'][0] = new Array(
     'New York',
     'Los Angeles'
);
//VALUE ARRAY
lists['USA'][1] = new Array(
     'New York',
     'Los Angeles'
);

*****************************************************************

If you would like to insert values from DB, you can do something like this:


lists['Australia'][0] = new Array(
<%
for counter = 1 to rs.recordcount
response.write rs("field1")
loop
%>

just some ideas....
 );
Looks good.  Just one more question then I'll close this out:  Is it true that I can only query the db with server-side scripting and therefore need to re-load the page each time the combo box is changed?  I'd like to avoid that if possible, but it doesn't seem do-able.
Thanks for all the help!

mv
I just found some JavaScript code that may be useful to you:

http://members.aol.com/grassblad/html/selCascade2.html
Hi mvasilevsky

You don't necessarily need to reload the page each time a new option is selected in the primary combobox. All you have to do is to preload all the options for the combobox all at once and store them in a javascript array like demostrated above. It may take a bit longer to preload all the options if you have thousands of options to load, but i think it will nevertheless avoid the page reload that is required when a new option is selected.

regards- :)