Click to See Complete Forum and Search --> : simple dynamic combo box question


LuigiX
02-17-2004, 02:26 AM
HI

I have two comboboxes on one form. I want the second one (cmbSpecification) to populate with values depending on the value selected in the first (cmbCategory).

I have the following code to populate the second combo:


rsSpecification.Source = "SELECT distinct spec_descript FROM data WHERE cat_descript = '" + Replace(rsSpecification__MMColParam, "'", "''") + "'"


The parameter "rsSpecification__MMColParam" is set to:


rsSpecification__MMColParam = Request.Form("cmbCategory")


'cept I know this aint right coz because the combos are on the same form.

The recordsets are working fine and the first combo is displaying just as intended.

Can anyone enlighten me?

Cheers

Luigi

buntine
02-17-2004, 09:54 AM
That code will work fine.. Provided the DB and tables exist.

What is your problem? You need to show us the code you are using to enter the data into the second combo box.

LuigiX
02-17-2004, 12:22 PM
Hi

There aint nothin happening in the second combobox cmbSpecification. This is populated from the recordset rsSpecification which has a "WHERE" clause on the first combobox cmbCategory.

BOth recordsets test fine.


Here's the code in full

Thanks for your help

Cheers

Luigi


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/conAsset.asp" -->
<%
Dim rsCategory
Dim rsCategory_numRows

Set rsCategory = Server.CreateObject("ADODB.Recordset")
rsCategory.ActiveConnection = MM_conAsset_STRING
rsCategory.Source = "SELECT distinct cat_descript FROM data"
rsCategory.CursorType = 0
rsCategory.CursorLocation = 2
rsCategory.LockType = 1
rsCategory.Open()

rsCategory_numRows = 0
%>
<%
Dim rsSpecification__MMColParam
rsSpecification__MMColParam = "cmbCategory"
If (Request("MM_EmptyValue") <> "") Then
rsSpecification__MMColParam = Request.Form
End If
%>
<%
Dim rsSpecification
Dim rsSpecification_numRows

Set rsSpecification = Server.CreateObject("ADODB.Recordset")
rsSpecification.ActiveConnection = MM_conAsset_STRING
rsSpecification.Source = "SELECT distinct spec_descript FROM data WHERE cat_descript = '" + Replace(rsSpecification__MMColParam, "'", "''") + "'"
rsSpecification.CursorType = 0
rsSpecification.CursorLocation = 2
rsSpecification.LockType = 1
rsSpecification.Open()

rsSpecification_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>Search for Assets</p>
<form name="form1" method="post" action="assets_2.asp">
<table width="350" border="0" cellspacing="2" cellpadding="2">
<tr>
<td><select name="cmbCategory" id="cmbCategory">
<option selected value="">Select a Value</option>
<%
While (NOT rsCategory.EOF)
%>
<option value="<%=(rsCategory.Fields.Item("cat_descript").Value)%>"><%=(rsCategory.Fields.Item("cat_descript").Value)%></option>
<%
rsCategory.MoveNext()
Wend
If (rsCategory.CursorType > 0) Then
rsCategory.MoveFirst
Else
rsCategory.Requery
End If
%>
</select></td>
<td><select name="cmbSpecification" id="cmbSpecification">
<option selected value="">Select</option>
<%
While (NOT rsSpecification.EOF)
%>
<option value="<%=(rsSpecification.Fields.Item("spec_descript").Value)%>"><%=(rsSpecification.Fields.Item("spec_descript").Value)%></option>
<%
rsSpecification.MoveNext()
Wend
If (rsSpecification.CursorType > 0) Then
rsSpecification.MoveFirst
Else
rsSpecification.Requery
End If
%>
</select></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Search"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>
<p>&nbsp;</p>
</body>
</html>
<%
rsCategory.Close()
Set rsCategory = Nothing
%>
<%
rsSpecification.Close()
Set rsSpecification = Nothing
%>

buntine
02-17-2004, 11:55 PM
Im having trouble finding errors within your code..

One suggestion.. Try replacing your while - wend code with a for - next loop.


rsSpecification.moveFirst
for i = 0 to rsSpecification.recordCount
if not rsSpecification.EOF then

'<option> code...

rsSpecification.moveNext
end if
next

LuigiX
02-19-2004, 12:48 PM
Hi

For anyone else with the same problem I eventually found what I was looking for at the following link.

http://www.codeproject.com/jscript/dynaframe.asp

Actually when I think about it now there was no way a combobox was going to populate itself based on another one in the same form using ASP without a trip to the server first.

Thanks for your help anyway

Cheers

Luigi

buntine
02-19-2004, 09:54 PM
Oh, haha, yes, to run ASP you need to process the form results on the server.. Thats the whole point of it.