台灣最大程式設計社群網站
線上人數
361
 
會員總數:245785
討論主題:189420
歡迎您免費加入會員
討論區列表 >> 專欄文章 >> N-階層的下拉式選單
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
N-階層的下拉式選單
價值 : 0 QP  點閱數:1041 回應數:0
樓主

站務人員 站長
門外漢
0 1580
542 9
發送站內信

捐贈 VP 給 站務人員
<%

Set cnn = Server.CreateObject("ADODB.Connection")

Set rs = Server.CreateObject("ADODB.Recordset")

cnn.Open "testdb", "sa", ""

SqlStr = "Select * From test1_tb"

set rs = cnn.execute(SqlStr)

%>

<form name="optionform" method="POST" action="">


<p align="center"> </p>

<div align="center">

<center>

<table border="1" width="883" height="27">

<tr>

<td width="158" height="1">請選擇(第一層):</td>

<td width="46" height="1">

<% If rs.EOF Then

response.write "資料庫中查無行庫資料"

response.end

rs.Close

Set rs=Nothing

Set cnn=Nothing

Else

%>

<select size="1" name="condition_choice" tabindex="6" onChange="redirect(this.options.selectedIndex)">

<% Response.write "<option =value=''></option>"

If rs.eof then

Response.write "<option =value=''></option>"

Else

d=0

While Not rs.EOF
response.write "<option value=" & chr(34) & rs("index") & chr(34) & ">"
& Trim(rs("cname")) & "</option>" & vbcrlf

d = d + 1

ReDim Preserve ig(d)

ig(d)= rs("index")

rs.MoveNext


wend

End if

End If

%>

</select>

</td>

<td width="158" height="1">請選擇(第二層):</td>

<td width="254" height="1">

<select size="1" name="content_choice" tabindex="7">

</select></td>

</tr>

</table>

</center>

</div>

<%

Response.Write "<script language='JavaScript'>" & vbcrlf

Response.Write "<!--" & vbcrlf

Response.Write "var optiongroups=document.optionform.condition_choice.options.length" & vbcrlf

Response.Write "var optiongroup=new Array(optiongroups)" & vbcrlf

Response.Write "for (i=0; i<optiongroups; i++)" & vbcrlf

Response.Write "optiongroup[i]=new Array()" & vbcrlf

for g = 1 to d

SqlStr = "Select * From test2_tb where index='" & ig(g) & "'"

Set rs = cnn.Execute(SqlStr)

j=0

While Not rs.EOF

Response.Write "optiongroup[" & ig(g) & "]" & "[" & j & "]" &
"=new Option(" & Chr(34) & rs("cname2") & Chr(34) & "," & Chr(34) &
Trim(rs("index2")) & Chr(34) & ")" & vbcrlf


j=j+1

rs.MoveNext

wend

next

Response.write "var temp=document.optionform.content_choice" & vbcrlf

Response.write "function redirect(x){" & vbcrlf

Response.write "for (m=temp.options.length-1;m>0;m--)" & vbcrlf

Response.write "temp.options[m]=null" & vbcrlf

Response.write "for (i=0;i<optiongroup[x].length;i++){" & vbcrlf

Response.write "temp.options[i]=new Option(optiongroup[x][i].text,optiongroup[x][i].value)" & vbcrlf

Response.write "}" & vbcrlf

Response.write "temp.options[0].selected=true" & vbcrlf

Response.write "}" & vbcrlf

Response.write "//-->" & vbcrlf

Response.write "</script>" & vbcrlf

rs.Close

Set rs=Nothing

Set cnn=Nothing

%>
本篇文章發表於2002-05-23 00:00
目前尚無任何回覆
   

回覆
如要回應,請先登入.