PDA

View Full Version : Need to populate list boxes!!


Famson3
12-03-2002, 04:09 PM
I need to populate two list boxes from one database.
The first list box will be populated, once de page loads, while de second list box will be populated based on the selection made in the first list box.
Both list boxes are on the same form.
Need a reply soon.
Thanks.

codefox
12-03-2002, 05:14 PM
Assuming that each list box is populated using 2 tables, say table1 and table2,

<%
sTable1Key = Request.Form("selTable1Vals")

oCon = Server.CreateObject("ADODB.Connection")
oCon.Open...
sSQLTable1 = "SELECT * FROM Table1"
rsTable1.Open sSQLTable1, oCon
%>
<form method="post" action="">
<select name="selTable1Vals" onChange="submit()">
<%
While Not rsTable1.EOF
If rsTable1("fld_val") = sTable1Key Then
%>
<option value="<% =rsTable1("fld_val") %>" selected><% =rsTable1("fld") %></option>
%>
<%
Else
%>
<option value="<% =rsTable1("fld_val") %>"><% =rsTable1("fld") %></option>
<%
End If
Wend
sSQLTable2 = "SELECT * FROM Table2 WHERE fld = " & sTable1Key
rsTable2.Open sSQLTable2, oCon
%>
<select name="selTable2Vals">
<%
While Not rsTable2.EOF
%>
<option value="<% =rsTable2("fld") %>" selected><% =rsTable2("fld") %></option>
<%
End If
Wend
%>


Well, I'm not sure if that would be of much use to you :)

glenngv
12-04-2002, 01:23 AM
if you want the 2nd combo to be populated without refreshing the page, you can use the double combo script here (http://www.javascriptkit.com/script/cut183.shtml)
Your asp code should generate a 2d javascript array of the items from the db.

glenngv
12-18-2002, 11:08 AM
Attached is the double-combo script from javascript.kit...