longmatch
Programmer
- Nov 1, 2001
- 406
Dear All:
I found this piece of code on the page used for linked-combo in ASP page. It works well. But I don't totally understand the logic behind code. Could anyone give me a concise explanation? By the way, could anybody tell me how to see the HTML oupput when this code run in Microsoft Visual Interdev 6.0?
thanks
Haijun
<!--#include file="Clssfdpage.asp"-->
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<form name="f1">
<%
Set rsX = Server.CreateObject("ADODB.Recordset"
sQuery = "SELECT category AS name, procedure AS model, " & _
"categoryID AS ManuID, procedureID AS ModelID " & _
"FROM CategoryProcedure"
rsX.Open sQuery, objConn, adOpenForwardOnly, _
adLockReadOnly, adCmdText
If rsX.EOF Then
Response.Write "No manufacturers.<BR>"
Else
' write the manufacturers listbox...
Response.Write "<SELECT NAME=""manufacturer"" " & _
" ONCHANGE=""manuselected(this);"" >"
' write the entry code for the javascript...
sJavaScript = "function manuselected(elem){" & vbCrlf & _
"for (var i = document.f1.model." & _
"options.length; i >= 0; i--){" & vbCrlf & _
"document.f1.model.options = null;" & _
vbCrlf
' loop through the recordset...
Do Until rsX.EOF
' is this a new manufacturer?
If sLastManufacturer <> rsX("Name"
Then
' if so, add an entry to the first listbox
sLastManufacturer = rsX("Name"
Response.Write "<OPTION VALUE=" & rsX("ManuID"
& _
">" & sLastManufacturer & "</OPTION>"
' and add a new section to the javascript...
sJavaScript = sJavaScript & "}" & vbCrlf & _
"if (elem.options[elem.selectedIndex].value==" & _
rsX("ManuID"
& "
{" & vbCrlf
End If
' and add a new model line to the javascript...
sJavaScript = sJavaScript & _
"document.f1.model.options[document." & _
"f1.model.options.length] = new Option('" & _
rsX("Model"
& "','" & rsX("ModelID"
& _
"');" & _
vbCrlf
rsX.MoveNext
Loop
' finish the manufacturer listbox...
Response.Write "</SELECT><br>"
' create the models listbox...
Response.Write "<SELECT NAME=""model"">"
Response.Write "<OPTION>[none currently selected]</OPTION>"
Response.Write "</SELECT>"
' put the last line on the javascript...
' and write it out...
sJavaScript = sJavaScript & vbCrlf & "}" & vbCrlf & _
"}" & vbCrlf
Response.Write "<SCRIPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write sJavaScript & vbCrlf & "</SCRIPT>" & vbCrlf
End If
rsX.Close
Set rsX = Nothing
%>
</form>
</BODY>
</HTML>
I found this piece of code on the page used for linked-combo in ASP page. It works well. But I don't totally understand the logic behind code. Could anyone give me a concise explanation? By the way, could anybody tell me how to see the HTML oupput when this code run in Microsoft Visual Interdev 6.0?
thanks
Haijun
<!--#include file="Clssfdpage.asp"-->
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<form name="f1">
<%
Set rsX = Server.CreateObject("ADODB.Recordset"
sQuery = "SELECT category AS name, procedure AS model, " & _
"categoryID AS ManuID, procedureID AS ModelID " & _
"FROM CategoryProcedure"
rsX.Open sQuery, objConn, adOpenForwardOnly, _
adLockReadOnly, adCmdText
If rsX.EOF Then
Response.Write "No manufacturers.<BR>"
Else
' write the manufacturers listbox...
Response.Write "<SELECT NAME=""manufacturer"" " & _
" ONCHANGE=""manuselected(this);"" >"
' write the entry code for the javascript...
sJavaScript = "function manuselected(elem){" & vbCrlf & _
"for (var i = document.f1.model." & _
"options.length; i >= 0; i--){" & vbCrlf & _
"document.f1.model.options = null;" & _
vbCrlf
' loop through the recordset...
Do Until rsX.EOF
' is this a new manufacturer?
If sLastManufacturer <> rsX("Name"
' if so, add an entry to the first listbox
sLastManufacturer = rsX("Name"
Response.Write "<OPTION VALUE=" & rsX("ManuID"
">" & sLastManufacturer & "</OPTION>"
' and add a new section to the javascript...
sJavaScript = sJavaScript & "}" & vbCrlf & _
"if (elem.options[elem.selectedIndex].value==" & _
rsX("ManuID"
End If
' and add a new model line to the javascript...
sJavaScript = sJavaScript & _
"document.f1.model.options[document." & _
"f1.model.options.length] = new Option('" & _
rsX("Model"
"');" & _
vbCrlf
rsX.MoveNext
Loop
' finish the manufacturer listbox...
Response.Write "</SELECT><br>"
' create the models listbox...
Response.Write "<SELECT NAME=""model"">"
Response.Write "<OPTION>[none currently selected]</OPTION>"
Response.Write "</SELECT>"
' put the last line on the javascript...
' and write it out...
sJavaScript = sJavaScript & vbCrlf & "}" & vbCrlf & _
"}" & vbCrlf
Response.Write "<SCRIPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write sJavaScript & vbCrlf & "</SCRIPT>" & vbCrlf
End If
rsX.Close
Set rsX = Nothing
%>
</form>
</BODY>
</HTML>