
August 14th, 2009, 06:49 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Posts: 8
Time spent in forums: 2 h 2 m 4 sec
Reputation Power: 0
|
|
|
Classic ASP/JScript - Need Help pls
I am trying to make the third drop box change according to the second one. And dont know what is wrong with the script.
Code:
<head>
<%
Dim myConnection 'Object
Dim myRS 'Object
Dim myConnectString 'String
Dim mySQL 'String
Dim myConnection2 'Object
Dim myRS2 'Object
'Dim myConnectString 'String
Dim mySQL2 'String
Dim StartAuthor 'String
Dim StartBook 'String
Dim Cnt 'Integer
Dim Cnta 'Integer
Dim ListBox1 'String
myConnectString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("author.mdb")
%>
<script language="javascript">
function listboxchange(p_index)
{
<%
%>
document.myform.listbox2.options.length = 0;
<%
'SQL Statement which groupes all authors together, to handle more than 1 book per author
mySQL = "SELECT * FROM Library Order By Author asc"
Set myConnection = CreateObject("ADODB.Connection")
myConnection.open myConnectString
'Get Recordset using our SQL
Set myRS = myConnection.Execute(mySQL)
%>
switch (p_index)
{
<%
'Loop Through all authors and books
Do Until myRS.eof
StartAuthor = myRS("Author")
Cnt = 0
%>
case "<%=StartAuthor%>" :
<%
'Loop until we disover a new author. Whilst author the same, add all of his/her books into grouped selection
do until myrs.eof or StartAuthor <> myRS("Author")
%>
document.myform.listbox2.options[<%=cnt%>]=new Option("<%=myRs("Book")%>","<%=myRs("Book")%>");
<%
Cnt = Cnt + 1
myrs.movenext
if myrs.eof then exit do
Loop
%>
break;
<%
Loop
myRS.close
Set myRS = nothing
%>
}
return true;
}
</script>
<script language="javascript">
function listboxchange2(p_index)
{
<%
%>
document.myform.listbox3.options.length = 0;
<%
mySQL2 = "SELECT * FROM Library Order By Book asc"
Set myConnection2 = CreateObject("ADODB.Connection")
myConnection2.open myConnectString
Set myRS2 = myConnection2.Execute(mySQL2)
%>
switch (p_index)
{
<%
Do Until myRS2.eof
StartBook = myRS2("Book")
Cnta = 0
%>
case "<%=StartBook%>" :
<%
do until myrs2.eof or StartBook <> myRS2("Book")
%>
document.myform.listbox3.options[<%=cnta%>]=new Option("<%=myRs2("Page")%>","<%=myRs2("Page")%>");
<%
Cnta = Cnta + 1
myrs2.movenext
if myrs2.eof then exit do
Loop
%>
break;
<%
Loop
myRS2.close
Set myRS2 = nothing
%>
}
return true;
}
</script>
<%
'Make ListBox1
'SQL Statement which selects each database entry for an author just once
'as we don't want the same name twice in our list box
mySQL = "SELECT DISTINCT Author FROM Library Order By Author asc"
Set myConnection = CreateObject("ADODB.Connection")
myConnection.open myConnectString
Set myRS = myConnection.Execute(mySQL)
'Make Drop down box Author list
do until myrs.eof
ListBox1 = ListBox1 & "<option value=""" & myRs("Author") & """>" & myRs("Author") & "</option>"
myRs.movenext
loop
myRS.close
Set myRS = nothing
myConnection.close
Set myConnection = nothing
%>
</head>
<body>
<form name="myform" action="" method="get">
<select name="listbox1" id="listbox1" onchange="javascript: listboxchange(this.options[this.selectedIndex].value);">
<option value="">Please Select</option>
<%=ListBox1%>
</select>
<select name="listbox2" onchange="javascript: listboxchange2(this.options[this.selectedIndex].value);">
<option value="">Please Select</option>
</select>
</form>
<select name="listbox3">
<option value="">Please Select</option>
</select>
</form>
</body>
</html>
Database pic is here: img199.imageshack.us/i/problempicture.jpg/
|