Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recordset doesn't work

Status
Not open for further replies.

mihalych

Programmer
Jul 24, 2003
27
US
Hello!
Could somebody help me with this.
When I create recordset and run query :

<% Dim intCategoryID, oNew %>

<SCRIPT LANGUAGE = &quot;VBScript&quot;>

Sub listBox_onChange()

<%Set rsSubcategory = connST.Execute (&quot;SELECT SubcategoryName FROM Subcategory WHERE CategoryID = ‘” & intCategoryID & “’”)
<%Do While Not rsSubcategory.EOF %>
Set oNew = document.createElement(&quot;&quot;)
form1.selEquipment.add oNew
oNew.InnerText = &quot;<%=rsSubcategory(&quot;SubcategoryName&quot;)&quot; <%rsSubcategory.MoveNext%>
<%Loop %>
End Sub
</SCRIPT>

The problem is that it cannot see the variable intCategoryID in a query string and does not populate another list box, but if I substitute ‘2’ instead of CategoryID it works well. The variable is working and displayed in the test label. Why? After all, can I create a recordset in subroutine on call? Is it correct to run server-side script inside client-side script?

Thanks

 
You can combine the server side code with client code but the server side code is executed first time you access that asp page and not on the client side event.

Also you have to use a self submit model and be shure you send CategoryID on that page.
Code:
<% Dim intCategoryID, oNew 
intCategoryID=Request(&quot;CategoryID&quot;)
%>
<SCRIPT LANGUAGE = &quot;VBScript&quot;>
Sub listBox_onChange()
<%
Set rsSubcategory = connST.Execute (&quot;SELECT SubcategoryName FROM Subcategory WHERE CategoryID = ” & intCategoryID)
Do While Not rsSubcategory.EOF
%>
Set oNew = document.createElement(&quot;<OPTION>&quot;) 
form1.selEquipment.add oNew 
oNew.InnerText = &quot;<%=rsSubcategory(&quot;SubcategoryName&quot;)%>&quot;
<%
 rsSubcategory.MoveNext
Loop
%>
End Sub
</SCRIPT>
This should be

________
George, M
 
Thank you for your response George. Actually, I have got a main page where in the left frame an asp page loaded containing two list boxes(on the same asp page). One of them populated with Categories names initially. The second list box with Subcategories names is empty. When user selects a category in Categories list box, the second list box should be loaded with appropriate subcategories. What would you recommend me in that case? Can the list boxes be on the same asp page? As I understood from you first response, the server side script esxecutes when page is loaded, but could it be reloaded without reloading page? Sorry, if I didn't get the first response.
Oleg
 
can you post the code here for the listboxes asp page?
i cant think at any example atm but might help working on yours.

________
George, M
 
Here is the category.asp page

<% Language=VBScript %>

<HTML>
<HEAD>
<% Dim intCategoryID, oNew %>
<% Dim connST, rsCategory, rsSubcategory, rsCategoryID, strDriver %>
<!-- create server object for database connection -->
<% strDriver = &quot;Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:\temp\sportime.mdb&quot; %>
<% Set connST = Server.CreateObject (&quot;ADODB.Connection&quot;) %>

<!-- retrieve data set records into database -->
<%
connST.Open strDriver
Set rsCategory = connST.Execute (&quot;SELECT CategoryID, CategoryName FROM Category&quot;)
%>
<SCRIPT LANGUAGE = &quot;VBScript&quot;>

' removes previous data from list box(Categories)

Sub selSport_onChange
for i = 0 to form1.selEquipment.length -1
form1.selEquipment.remove (1)
next
End Sub

'creates Subcategory recordset and populate Subcategory list box

<%Set rsSubcategory = connST.Execute (&quot;SELECT SubcategoryName FROM Subcategory WHERE CategoryID = '&quot; & intCategoryID & &quot;'&quot;)%>
<%Do While Not rsSubcategory.EOF%>
Set oNew = document.createElement(&quot;<OPTION Name=XX>&quot;)
form1.selEquipment.add oNew
oNew.InnerText = &quot;<%=rsSubcategory(&quot;SubcategoryName&quot;)%>&quot;
<%rsSubcategory.MoveNext%>
<%Loop %>

</SCRIPT>

<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>

</HEAD>
<body background=&quot;_themes/rmnsque/romtextb.jpg&quot; bgcolor=&quot;#CCCC99&quot; text=&quot;#000000&quot; link=&quot;#996600&quot; vlink=&quot;#666666&quot; alink=&quot;#336600&quot;><!--mstheme--><font face=&quot;Times New Roman, Times&quot;>

<form method=&quot;POST&quot; target=&quot;main&quot; action=&quot;&quot; onSubmit=&quot;&quot; id=form1 name=frmMain LANGUAGE=javascript ondblclick=&quot;return form1_ondblclick()&quot;>
<!--webbot bot=&quot;SaveResults&quot; startspan U-File=&quot;_private/form_results.txt&quot;
S-Format=&quot;TEXT/CSV&quot; S-Label-Fields=&quot;TRUE&quot; B-Reverse-Chronology=&quot;FALSE&quot;
S-Builtin-Fields --><input TYPE=&quot;hidden&quot; NAME=&quot;VTI-GROUP&quot; VALUE=&quot;0&quot;><!--webbot
bot=&quot;SaveResults&quot; endspan i-checksum=&quot;43374&quot; -->
<p style=&quot;word-spacing: 0; margin-top: 0; margin-bottom: 0&quot;>Sport name:</p>
<p style=&quot;word-spacing: 0; margin-top: 0; margin-bottom: 0&quot;>
<!-- display category name in selection list -->

<select size=&quot;1&quot; name=selSport>
<% Do While Not rsCategory.EOF%>
<option value=<%=rsCategory(&quot;CategoryID&quot;)%>><% =rsCategory(&quot;CategoryName&quot;)%>
<% rsCategory.MoveNext %>
<% Loop %>
</select></p>

<p style=&quot;word-spacing: 0; margin-top: 6; margin-bottom: 0&quot;>Equipment type:</p>
<p style=&quot;word-spacing: 0; margin-top: 0; margin-bottom: 0&quot;>
<select size=&quot;1&quot; name=&quot;selEquipment&quot;>
<option></option>
</select></p>

<% connST.Close %>

</form>
<form method=&quot;POST&quot; action=&quot;product.asp&quot; onSubmit=&quot; &quot; id=form2 name=form2>
<!--webbot bot=&quot;SaveResults&quot; startspan U-File=&quot;_private/form_results.txt&quot;
S-Format=&quot;TEXT/CSV&quot; S-Label-Fields=&quot;TRUE&quot; --><input TYPE=&quot;hidden&quot; NAME=&quot;VTI-GROUP&quot; VALUE=&quot;1&quot;><!--webbot
bot=&quot;SaveResults&quot; endspan i-checksum=&quot;43406&quot; -->
<p style=&quot;word-spacing: 0; margin-top: 0; margin-bottom: 0&quot;>Keyword search:</p>
<p style=&quot;word-spacing: 0; margin-top: 0; margin-bottom: 0&quot;><input type=&quot;text&quot; name=&quot;txtSearch&quot; size=&quot;20&quot;><a href=&quot;Main_page.htm&quot; target=&quot;main&quot;><input type=&quot;button&quot; value=&quot;GO!&quot; name=&quot;cmdSearch&quot;></a></p>
<INPUT type=&quot;submit&quot; value=&quot;Submit&quot; id=submit name=submit>
</form>
<p>&nbsp;</p>
<!--mstheme--></font></body>

</FORM>

</HTML>


 
This should work, not shure on the settings but should work.


<% Language=VBScript %>

<HTML>
<HEAD>
<% Dim intCategoryID, oNew
intCategoryID=Request(&quot;catID&quot;)
'this line is for empty intCategoryID
if intCategoryID=&quot;&quot; then intCategoryID=1
%>
<% Dim connST, rsCategory, rsSubcategory, rsCategoryID, strDriver %>
<!-- create server object for database connection -->
<% strDriver = &quot;Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:\temp\sportime.mdb&quot; %>
<% Set connST = Server.CreateObject (&quot;ADODB.Connection&quot;) %>

<!-- retrieve data set records into database -->
<%
connST.Open strDriver
Set rsCategory = connST.Execute (&quot;SELECT CategoryID, CategoryName FROM Category&quot;)
%>
<SCRIPT LANGUAGE = &quot;VBScript&quot;>

' removes previous data from list box(Categories)

Sub selSport_onChange
for i = 0 to form1.selEquipment.length -1
form1.selEquipment.remove (1)
next
End Sub

'creates Subcategory recordset and populate Subcategory list box

<%Set rsSubcategory = connST.Execute (&quot;SELECT SubcategoryName FROM Subcategory WHERE CategoryID = '&quot; & intCategoryID & &quot;'&quot;)%>
<%Do While Not rsSubcategory.EOF%>
Set oNew = document.createElement(&quot;<OPTION Name=XX>&quot;)
form1.selEquipment.add oNew
oNew.InnerText = &quot;<%=rsSubcategory(&quot;SubcategoryName&quot;)%>&quot;
<%rsSubcategory.MoveNext%>
<%Loop %>

</SCRIPT>

<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>

</HEAD>
<body background=&quot;_themes/rmnsque/romtextb.jpg&quot; bgcolor=&quot;#CCCC99&quot; text=&quot;#000000&quot; link=&quot;#996600&quot; vlink=&quot;#666666&quot; alink=&quot;#336600&quot;><!--mstheme--><font face=&quot;Times New Roman, Times&quot;>

<form method=&quot;POST&quot; target=&quot;main&quot; action=&quot;&quot; onSubmit=&quot;&quot; id=form1 name=frmMain LANGUAGE=javascript ondblclick=&quot;return form1_ondblclick()&quot;>
<!--webbot bot=&quot;SaveResults&quot; startspan U-File=&quot;_private/form_results.txt&quot;
S-Format=&quot;TEXT/CSV&quot; S-Label-Fields=&quot;TRUE&quot; B-Reverse-Chronology=&quot;FALSE&quot;
S-Builtin-Fields --><input TYPE=&quot;hidden&quot; NAME=&quot;VTI-GROUP&quot; VALUE=&quot;0&quot;><!--webbot
bot=&quot;SaveResults&quot; endspan i-checksum=&quot;43374&quot; -->
<p style=&quot;word-spacing: 0; margin-top: 0; margin-bottom: 0&quot;>Sport name:</p>
<p style=&quot;word-spacing: 0; margin-top: 0; margin-bottom: 0&quot;>
<!-- display category name in selection list -->

<select size=&quot;1&quot; name=selSport onchange=&quot;document.location='category.asp?catID='+this.value&quot;>
<% Do While Not rsCategory.EOF%>
<option value=<%=rsCategory(&quot;CategoryID&quot;)%>><% =rsCategory(&quot;CategoryName&quot;)%>
<% rsCategory.MoveNext %>
<% Loop %>
</select></p>

<p style=&quot;word-spacing: 0; margin-top: 6; margin-bottom: 0&quot;>Equipment type:</p>
<p style=&quot;word-spacing: 0; margin-top: 0; margin-bottom: 0&quot;>
<select size=&quot;1&quot; name=&quot;selEquipment&quot;>
<option></option>
</select></p>

<% connST.Close %>

</form>
<form method=&quot;POST&quot; action=&quot;product.asp&quot; onSubmit=&quot; &quot; id=form2 name=form2>
<!--webbot bot=&quot;SaveResults&quot; startspan U-File=&quot;_private/form_results.txt&quot;
S-Format=&quot;TEXT/CSV&quot; S-Label-Fields=&quot;TRUE&quot; --><input TYPE=&quot;hidden&quot; NAME=&quot;VTI-GROUP&quot; VALUE=&quot;1&quot;><!--webbot
bot=&quot;SaveResults&quot; endspan i-checksum=&quot;43406&quot; -->
<p style=&quot;word-spacing: 0; margin-top: 0; margin-bottom: 0&quot;>Keyword search:</p>
<p style=&quot;word-spacing: 0; margin-top: 0; margin-bottom: 0&quot;><input type=&quot;text&quot; name=&quot;txtSearch&quot; size=&quot;20&quot;><a href=&quot;Main_page.htm&quot; target=&quot;main&quot;><input type=&quot;button&quot; value=&quot;GO!&quot; name=&quot;cmdSearch&quot;></a></p>
<INPUT type=&quot;submit&quot; value=&quot;Submit&quot; id=submit name=submit>
</form>
<p> </p>
<!--mstheme--></font></body>

</FORM>

</HTML>


________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top