<% ' will database link string, SQL narration, form the first form string variable (colorlist), the first form name ' Color, form a second form string variable (fruitlist), 21st form name fruit, form a third form string variable ' ( Pricelist), the third form name, price, when the information is processed and then returned to the main program by calling the applet, note that some of the parameters are passed back to the main program in a byref manner, and some of the parameters are returned in ByVal ' Purple bold text is byref. Please view the part of the following program directly
Mydsn= "PROVIDER=SQLOLEDB; Data Source=jackal; Initial catalog=pubs; User Id=sa; Password= "
Strsql= "Select Color.color, Fruit.fruit, price.cost from color join fruit on color.id=fruit. Colorid join Price. Fruitid=fruit.id ORDER BY Color.id "
Call Listmaker (MyDSN, strSQL, colorlist, "color", fruitlist, "fruit", pricelist, "Price", Pubevent, Pubfun, "myForm")% ><form name= "MyForm" Method=post action=listbox2.asp>
Color:
<%= colorlist%>
SUB Listmaker (MyDSN, Strsql,byref List1, listname1, ByRef list2, Listname2, ByRef list3, Listname3, ByRef myevent, ByRef m Yfun, MyForm)
Set my_conn = Server.CreateObject ("ADODB. Connection ")
My_conn.open MyDSN
Set Rs=my_conn.execute (strSQL)
' Use the ColorList string variable to create the first drop-down menu Html source code.
colorlist= "<select name=" & listname1
Colorlist=colorlist & "onchange=" "Buildkey"
Colorlist=colorlist & "(This.selectedindex);" " > "
' Use the Fruitlist string variable to create the Html source for the second Drop-down menu.
fruitlist= "<select name=" & listname2
Fruitlist=fruitlist & "onchange=" "Buildkey1"
Fruitlist=fruitlist & "(This.selectedindex);" " > "
' Use the Pricelist string variable to create a third drop-down menu Html source code.
pricelist= "<select name=" & Listname3 & ">"
' Here, some of the initial variable values are used as the flags for performing operations below.
Loopcounter=0
Lastvalue=rs (0)
Lastvalue2=rs (1)
ReDim Temparray (1)
' Thisgroupcount represents a certain color with several kinds of fruit.
Thisgroupcount=0
' Thissubgroupcount represents a certain kind of fruit with several prices, and when the fruit is transformed, the Thissubgroupcount will return to zero and then ' accumulate '.
Thissubgroupcount=0
' Howmanygroups represents a total of several colors
Howmanygroups=0
' Howmanysubgroups represents a total of several fruits, and when the color changes, the howmanysubgroups will return to zero and then ' accumulate '.
Howmanysubgroups=0
Do UNTIL rs.eof
Thisvalue=rs (0)
Thisvalue2=rs (1)
Thisvalue3=rs (2)
' If the fruit name is found to change, and the current fruit is a color of the first fruit, such as: Red ← apple ' or: yellow ← Orange When the script in the color tag (in order to make it easier to separate the script area), and then define the fruit name to the key array values,
' Then define the length of the array for the first few colors of the key1[[the first few fruits].
If Thisvalue2<>lastvalue2 Then
If Howmanysubgroups=0 Then
TEMPSTR1=TEMPSTR1 & "//" & Lastvalue & vbCrLf
TEMPSTR2=TEMPSTR2 & "//" & Lastvalue & vbCrLf
End If
TEMPSTR2=TEMPSTR2 & "key1[" & Howmanygroups & "[" & Howmanysubgroups &
"]=new Array (" & Thissubgroupcount & ");" & vbCrLf
TEMPSTR1=TEMPSTR1 & "key[" & Howmanygroups & "[" & Howmanysubgroups &
"]=" "" & Lastvalue2 & "" ";" & VbCRLF
Howmanysubgroups=howmanysubgroups+1
Thissubgroupcount=0
Lastvalue2=thisvalue2
End If
The results of the implementation are as follows
Red
key[0][0]= "Apple";
Key[0][1]= "Lotus Mist";
key[0][2]= "Plum";
Yellow
Key[1][0]= "Orange";
key[1][1]= "Grapefruit";
Green
key[2][0]= "ba le";
key[2][1]= "Watermelon";
key[2][2]= "Dates";
Red
Key1[0][0]=new Array (3);
Key1[0][1]=new Array (3);
Key1[0][2]=new Array (3);
Yellow
Key1[1][0]=new Array (3);
Key1[1][1]=new Array (3);
Green
Key1[2][0]=new Array (3);
Key1[2][1]=new Array (3);
Key1[2][2]=new Array (3);
' If you find a color name change, define the key[of the first few colors ' array values,
' Then define the length of the array of key1[, the reason for the repetition definition has already been said before, then ' after the howmanygroups (color kind) value plus one, and the fruit kind Count value (thisgroupcount) to zero if thisvalue< >lastvalue Then
Tempstr=tempstr & "key[" & howmanygroups & "]=new Array (" & Howmanysubgroups & ");" & _vbcrlf
Tempstr=tempstr & "key1[" & howmanygroups & "]=new Array (" & Howmanysubgroups & ");" & _vbcrlf
Thisgroupcount=0
Howmanygroups=howmanygroups+1
Howmanysubgroups=0
End If
The results of the implementation are as follows
Key=new Array (3);
Key1=new Array (3);
Key[0]=new Array (3);
Key1[0]=new Array (3);
Key[1]=new Array (2);
Key1[1]=new Array (2);
Key[2]=new Array (3);
Key1[2]=new Array (3)
' If thisgroupcount=0 represents the current color change, then write the name of the color to the color pull-down menu if thisgroupcount=0 then
ColorList =colorlist & "<option>" & Thisvalue & "</option>" & vbCrLf
End If
' If the thissubgroupcount=0 represents the current fruit change, it is easier to separate the fruit name from the price area by adding a fruit name tag to the first few colors of the key1[[the first few fruits] [the first few ' price] array values.
If Thissubgroupcount=0 Then
TEMPSTR3=TEMPSTR3 & "//" & Lastvalue2 & vbCrLf
End If
' Defines the key1[of the first several colors [the first few fruits] [the first several price] array values.
TEMPSTR3=TEMPSTR3 & "key1[" & Howmanygroups & "[" & Howmanysubgroups & "] [" & Thissubgroupcount & Amp "]=" "" & Thisvalue3 & "" "," & VbCRLF ' execution results:
Frequency fruit
key1[0][0][0]= "10 Yuan";
key1[0][0][1]= "20 Yuan";
key1[0][0][2]= "30 yuan";
Lotus Mist
Key1[0][1][0]= "40 Yuan";
key1[0][1][1]= "50 Yuan";
key1[0][1][2]= "60 Yuan";
Plum
key1[0][2][0]= "70 Yuan";
key1[0][2][1]= "80 Yuan";
Key1[0][2][2]= "90 Yuan";
Orange
key1[1][0][0]= "100 Yuan";
key1[1][0][1]= "110 Yuan";
key1[1][0][2]= "120 Yuan";
Grapefruit
key1[1][1][0]= "130 Yuan";
key1[1][1][1]= "140 Yuan";
key1[1][1][2]= "150 Yuan";
Ba Le
key1[2][0][0]= "160 Yuan";
key1[2][0][1]= "170 Yuan";
key1[2][0][2]= "180 yuan";
Watermelon
key1[2][1][0]= "190 Yuan";
key1[2][1][1]= "200 Yuan";
key1[2][1][2]= "210 yuan";
Dates
key1[2][2][0]= "220 Yuan";
key1[2][2][1]= "230 Yuan";
key1[2][2][2]= "240 yuan";
' If this is the first color and the name of the fruit is changing, write the name of the fruit to the fruit pull-down menu if howmanygroups=0 then
If Thissubgroupcount=0 Then
fruitlist = fruitlist & "<option>" & thisvalue2 & "</option>" & vbCrLf
End If
End If
' If it's the first color, and it's the first fruit, write the price to the prices Pull-down menu.
If Howmanygroups=0 Then
If Howmanysubgroups=0 Then
Pricelist = pricelist & "<option>" & Thisvalue3 & "</option>" & vbCrLf
End If
End If
LOOP
' Don't forget the last key[. The array length of the first few colors and key1[is undefined.
Tempstr=tempstr & "key[" & Howmanygroups & _
"]=new Array (" & Howmanysubgroups+1 & ");" & _
vbCrLf
Tempstr=tempstr & "key1[" & Howmanygroups & _
"]=new Array (" & Howmanysubgroups+1 & ");" & _
vbCrLf
' Don't forget the last key[. The array length of the first several colours [the first few fruits] and key1[[the first few fruits] has not been defined.
TEMPSTR2=TEMPSTR2 & "key1[" & Howmanygroups & "[& Howmanysubgroups &"]=new Array ("& Thissubgro Upcount & ");" & _vbcrlf
tempstr1= TempSTR1 & "key[" & Howmanygroups & "[" & Howmanysubgroups & "]=" "" & Lastvalue2 & ""; "& VbCRLF Tempstr=tempstr & TempSTR1 & TempSTR2 & TempSTR3
' Put the color Pull-down menu at the end of the
Colorlist=colorlist & "</select>"
' Make an end of the Fruit pull-down menu
fruitlist= fruitlist & "</select>"
' Put the price pull-down menu at the end of the
pricelist= pricelist & "</select>"
' Start with the key and Key1 array and don't forget to define it.
' It's done, you can close the database.
Rs.close
Set rs=nothing
My_conn.close
Set my_conn=nothing
' First generation Buildkey, this side is not difficult, the principle has been explained above, the author no longer repeat, the implementation of the results are:
function Buildkey (num)
{
Buildkey1 (0);
document.myform.fruit.selectedindex=0;
for (ctr=0;ctr<key[num].length;ctr++)
{
Document.myform.fruit.options[ctr]=new Option (key[num][ctr],key[num][ctr]);
}
Document.myform.fruit.length=key[num].length;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.