Code:
& lt% @ Language = VBscript % & gt
& lt%
'************************************************************************************************************
'
Using a single file version selection drop-down link to realize database version
'
'
'************************************************************************************************************
% & gt
& lthtml & gt
Drop-down list case of & lttitle & gt link
& ltbody & gt
& lt scripting language = "javascript">
& lt! -
//The onchange event function of the first select
Function RefreshSelect(o, n)
{ if(n = = 2)document . mxh . elements[" s "+(n+ 1)]。 innerHTML= " "
if(o.options[o.selectedIndex].value=="0 ")
document.mxh.elements["s"+n]。 innerHTML= " "
other
{
document . mxh . BTN . disabled = false
window . frames[' hidden frame ']. location . href = ' multiselect . ASP? PID = '+o . options[o . selectedindex]。 Value+"&; n="+n
}
}
Function getSelected ()
{
for(I = 1; I<4; i++)
{
if(document . mxh . elements[" s "+I])。 selectedIndex & gt- 1)
Alert ("You selected:" +document.mxh.elements ["s"+i "). options[document . mxh . elements[" s "+I]。 Selectedindex]。 value+"-"+document . mxh . elements[" s "+I]。 Options.
}
}
//-& gt;
& lt/script & gt;
& ltform name = mxh & gt
& ltInput value= "The rest of the page will not change." style = " width:90% " & gt; & ltbr & gt
& ltselect name = " s 1 " onchange = " refresh select(this,2)" & gt; & ltoption value="0 ">- Please select-
& ltselect name = " S2 " onchange = " refresh select(this,3)" & gt; & ltoption value="0 ">- Please select-
& ltselect name="s3 " >& lt/select & gt;
& lt input type = "button" name =' BTN' disabled = true value = "view selection" onclick = "get selected()" & gt;;
& lt/form & gt;
& ltiframe name = " hidden frame " style = " display:none " & gt。 & lt/iframe & gt;
& lt/body & gt;
& lt%
This program is divided into two parts, one is used to submit and generate new data, and the other is used to initialize.
In fact, this is not very good for understanding. I hope you can understand for a while. It is best to understand in two grades.
1, the initialization part begins, and the main work is:
A. Initialize the first drop-down list
Dim sql,rs,cn,I
i = 0
Set cn = Server. CreateObject("ADODB。 Connect ")
cn。 Open "Provider=Microsoft。 Jet. OLEDB.4.0 data source = "& server. MapPath("MultiSelect.mdb ")
If required. QueryString("pid") = ""So
Initialization part
Set rs = cn. Execute ("Select * from pid=0")
Response. Write "< scripting language = 'javascript' >& ampvbCrLf
Response. Write "var arr1= new array ()"&; vbCrLf
Response. Write "var arr 2 = new Array()" & amp; vbCrLf
Not rs. eof
Response. Write down arr1["&; I&"] ='"&; RS(" id ")& amp; “& ampvbCrLf
Response. Write "arr2 ["&; I&"] ='"&; Rs ("name") & amp“& ampvbCrLf
i = i + 1
rs。 next step
line
For safety reasons.
Response. Write "window.onload = newfunction () {"&; vbCrLf
Response. Write "select1= document.mxh.s1"&; vbCrLf
Response. Write for (I =1; I< arr1.length+1; i++)“& amp; vbCrLf
Response. Write "select1.options [I] = new option (arr2 [I-1], arr1[I-1])"&; vbCrLf
Response. Write "}"&; vbCrLf
Response. Write "& lt/script >& ampvbCrLf"
other
Processing data submission
StrTreeId = request. Query string ("pid")
If strTreeId = "",then strTreeId = 0.
If IsNumeric(strTreeId) = False, then strTreeId = 0.
Response. clear
Response. Write "< scripting language = 'javascript' >& ampvbCrLf
Response. Write "choose" & request. query string(" n ")& amp; " = window . parent . document . mxh . s " & amp; Request. query string(" n ")& amp; vbCrLf
Response. Write "choose" & request. query string(" n ")& amp; ".innerHTML =“”& amp; vbCrLf
Response. Write "choose" & request. query string(" n ")& amp; ".options[0]= new option("- please select-"",""0" ")"&; vbCrLf
Set rs = cn. execute(" SELECT * FROM Area Where PID = " & amp; Request. QueryString("pid "))
Not rs. eof
Response. Write "choose" & request. query string(" n ")& amp; ".Option [Select]&; Request. query string(" n ")& amp;" . length] = new option ("& trim (RS ("name "))&; ,' " & ampRS(" id ")& amp; )" & ampvbCrLf
rs。 next step
line
Response. Write "& lt/script >& ampvbCrLf"
If ... it will be over.
rs。 close
Set rs = none
cn。 close
Set cn = none
% & gt
database
/ 1049287.html