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

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

捐贈 VP 給 站務人員
***********************************
<!-- e-mail:RueyHO@ms11.hinet.net -->

<HTML>
<TITLE>XX補習班</TITLE>
<BODY>

請選擇要報名的班別
<Form>
<select id=leftMenu name=leftMenu onchange="selectChange();">
</select>
<SELECT id=rightMenu name=rightMenu>
</SELECT>
<INPUT type=button value="報名確定" onclick="ok();">
</FORM>
</BODY>
</HTML>
<SCRIPT Language="JavaScript">
var strMenu;
var arrMenu;
var leftmenu;
var rightmenu;
var tmpIDX;
var menu=new Array();

menu[0]="asp速成班+04/01 11:00-12:00";
menu[1]="asp速成班+04/02 11:00-12:00";
menu[2]="asp速成班+04/03 11:00-12:00";
menu[3]="網路速成班+04/04 11:00-12:00";
menu[4]="網路速成班+04/05 11:00-12:00";
menu[5]="網路速成班+04/06 11:00-12:00";
menu[6]="視窗速成班+04/07 11:00-12:00";
menu[7]="視窗速成班+04/08 11:00-12:00";
menu[8]="視窗速成班+04/09 11:00-12:00";
menu[9]="視窗全能班+04/11 11:00-12:00";
menu[10]="視窗全能班+04/12 11:00-12:00";
menu[11]="視窗全能班+04/13 11:00-12:00";

for(tmpIDX=0;tmpIDX<menu.length;tmpIDX++){
arrtmp1= menu[tmpIDX].split("+");
if(!selectCheck(strMenu,arrtmp1[0])){
if(tmpIDX==0)
strMenu=arrtmp1[0];
else
strMenu=strMenu+','+arrtmp1[0];
}
}

leftmenu=strMenu.split(',');
selectAdd("leftMenu",leftmenu);

for(tmpIDX=0;tmpIDX<menu.length;tmpIDX++){
arrtmp1= menu[tmpIDX].split("+");
if(leftmenu[0]==arrtmp1[0]){
if(tmpIDX==0)
strMenu=arrtmp1[1];
else
strMenu=strMenu+','+arrtmp1[1];
}
}

rightmenu=strMenu.split(',');
selectAdd("rightMenu",rightmenu);

//<!-- 用途: 將Select填入值
function selectAdd(sMenu,arrSelect){
var tmpIDX;

for(tmpIDX=0;tmpIDX<arrSelect.length;tmpIDX++){
var oOption = document.createElement("OPTION");
oOption.text=arrSelect[tmpIDX];
oOption.value=arrSelect[tmpIDX];
document.all(sMenu).add(oOption);
}
}

//<!-- 用途: 將Select移除值
function selectDel(sMenu,stritem){
var tmpIDX;

document.all(sMenu).remove(stritem);
}
//<!-- 用途: 將Select移除值
function selectChange(){
var tmpIDX;

for(tmpIDX=0;tmpIDX<document.all.tags('SELECT').item(0).options.length;tmpIDX++)
selectDel("rightMenu",document.all('rightMenu').value)
selectDel("rightMenu",0)
selectDel("rightMenu",1)
arrtmp1="";
strMenu="";
for(tmpIDX=0;tmpIDX<menu.length;tmpIDX++){

arrtmp1= menu[tmpIDX].split("+");
if(document.all('leftMenu').value==arrtmp1[0]){
//alert(menu[tmpIDX]);
if(tmpIDX==0)
strMenu=arrtmp1[1];
else
strMenu=strMenu+','+arrtmp1[1];
}
}

rightmenu=strMenu.split(',');
selectAdd("rightMenu",rightmenu);
}
//<!-- 用途: 檢查Select值
function selectCheck(sMenu,strItem){
var arrMenu;
var tmpIDX;

if(sMenu==null)
return false;
arrMenu=sMenu.split(',');
for(tmpIDX=0;tmpIDX<arrMenu.length;tmpIDX++){
if(arrMenu[tmpIDX]==strItem)
return true;
}
return false;
}
//<!-- 用途: 顯示Select值
function ok(){
alert('leftMenu='+document.all("leftMenu").value+'\nrightMenu='+document.all("rightMenu").value);
}
</Script>
<script language="javascript">
</script>


--------------------------------------------------------------------------
兩個Table的選取方式

回應者: 沒營養甘蔗 kyt@ms1.accmail.com.tw

<% Option Explicit %>
<HTML>
<HEAD>
<TITLE>動態二階變動下拉式選單</TITLE>
</HEAD>
<BODY>
<FORM Name="FormA">
<%
Dim ADORs
Dim SQL
Dim thisvalue,lastvalue,Type_Count,Book_Count,Temp_Str
Set ADORs = Server.CreateObject("ADODB.Recordset")
ADORs.ActiveConnection = Application("Conn")
ADORs.CursorType=0
ADORs.LockType=1
SQL = "select book_type,book_name from book order by book_type"
ADORs.Open SQL
Response.Write("書籍種類<Select name='type' OnChange='changeselect(this.selectedIndex);'>")
Type_Count = 0
Book_Count = 0
Dim Test
Do Until ADORs.EOF
thisvalue = ADORs(0)
If thisvalue <> lastvalue Then
Response.Write("<option>" & thisvalue & "</option>")
Temp_Str = "key[" & Type_Count & "]=new Array(" & Book_Count & ");" & vbCRLF & Temp_Str
Type_Count = Type_Count + 1
Book_Count = 0
End If
Temp_Str = Temp_Str & "key[" & (Type_Count-1) & "][" & Book_Count & "]=" & ADORs(1)& ";" & vbCRLF
lastvalue = thisvalue
ADORs.MoveNext
Book_Count = Book_Count + 1
loop
Response.Write("</Select><BR>")
Response.Write("書籍名稱<Select Name='book'>")
Response.WRite("</Select>")
Temp_Str = "key = new Array(" & Type_Count & ");" & vbCRLF & Temp_Str
%>
</FORM>
</BODY>
</HTML>
<%
Response.Write("<Script language='JavaScript'>")
Response.Write(Temp_Str)
Response.Write("function changeselect(num) {")
Response.Write("document.FormA.book.selectedIndex=0;")
Response.Write("document.FormA.book.length=key[num].length;")
Response.Write("for (var i=0;i<key[num].length;i++) {")
Response.Write("document.FormA.book.options[i] = new Option(key[num][i]);")
Response.Write("}")
Response.Write("}")
Response.Write("</Script>")
ADORs.Close
Set ADORs = Nothing
%>

--------------------------------------------------------------------------

回應者: simon

1.相同table的這郭小程式需要作修改(已經加註解了)
<HTML>
<HEAD>
<TITLE>動態二階變動下拉式選單</TITLE>
</HEAD>
<BODY>
<FORM Name="FormA">
<%
Dim ADORs
Dim SQL
Dim thisvalue,lastvalue,Type_Count,Book_Count,Temp_Str
Set ADORs = Server.CreateObject("ADODB.Recordset")
ADORs.ActiveConnection = Application("Conn")
ADORs.CursorType=0
ADORs.LockType=1
SQL = "select book_type,book_name from book order by book_type"
ADORs.Open SQL
Response.Write("書籍種類<Select name='type' OnChange='changeselect(this.selectedIndex);'>")
Type_Count = 0
Book_Count = 0
Dim Test
Do Until ADORs.EOF
thisvalue = ADORs(0)
If thisvalue <> lastvalue Then
Response.Write("<option>" & thisvalue & "</option>")
Temp_Str = "key[" & Type_Count & "]=new Array(" & Book_Count & ");" & vbCRLF & Temp_Str
Type_Count = Type_Count + 1
Book_Count = 0
End If
Temp_Str = Temp_Str & "key[" & (Type_Count-1) & "][" & Book_Count & "]=" & Book_Count & ";" & vbCRLF
^^^^^^^^^^--->必須改為 "rs(1)" 才有用喔[又打雙引號],否則會出現沒有加 ; 的錯誤

lastvalue = thisvalue
ADORs.MoveNext
Book_Count = Book_Count + 1
loop
Response.Write("</Select><BR>")
Response.Write("書籍名稱<Select Name='book'>")
Response.WRite("</Select>")
Temp_Str = "key = new Array(" & Type_Count & ");" & vbCRLF & Temp_Str
%>
</FORM>
</BODY>
</HTML>
<%
Response.Write("<Script language='JavaScript'>")
Response.Write(Temp_Str)
Response.Write("function changeselect(num) {")
Response.Write("document.FormA.book.selectedIndex=0;")
Response.Write("document.FormA.book.length=key[num].length;")
Response.Write("for (var i=0;i<key[num].length;i++) {")
Response.Write("document.FormA.book.options[i] = new Option(key[num][i]);")
Response.Write("}")
Response.Write("}")
Response.Write("</Script>")
ADORs.Close
Set ADORs = Nothing
%>

第二點
sql="select 銀行.名稱, 專案.名稱 from 銀行 join 專案 on 銀行.代碼=專案.代碼 order by 銀行.代碼"

Set adocon = Server.CreateObject("ADODB.Connection")
adocon.ConnectionString = "Driver={SQL Server};Server=(local);" & _
"UID=sa;PWD=;"
adocon.Open
adocon.DefaultDatabase = "BANK"
set rs = adocon.Execute(sql) '執行查詢動作
Response.Write("選擇銀行<Select name=""type"" OnChange=""changeselect(this.selectedIndex);"">")
Type_Count = 0
Book_Count = 0
Do Until rs.EOF
thisvalue = rs(0)
if thisvalue <> lastvalue Then
Response.Write("<option>" & thisvalue & "</option>")
Temp_Str = "key[" & Type_Count & "]=new Array(" & Book_Count & ");" & vbCRLF & Temp_Str
Type_Count = Type_Count + 1
Book_Count = 0
End If
Temp_Str = Temp_Str & "key[" & Type_Count & "][" & Book_Count & "]=""" & rs(1) &""";" & vbCRLF
lastvalue = thisvalue
rs.MoveNext
Book_Count = Book_Count + 1
loop
Response.Write("</Select>")
Response.Write("專案名稱<Select Name=""PROJECT"">")
Response.WRite("</Select>")
Temp_Str = "key[" & Type_Count & "]=new Array(" & Book_Count & ");" & vbCRLF & Temp_Str
Temp_Str = "key = new Array(" & Type_Count & ");" & vbCRLF & Temp_Str

Response.Write("<Script language=""JavaScript"">")
Response.Write(Temp_Str)
Response.Write("function changeselect(num) {")
Response.Write("document.FormA.PROJECT.selectedIndex=0;")
Response.Write("document.FormA.PROJECT.length=key[num].length;")
Response.Write("for (var i=0;i<key[num].length;i++) {")
Response.Write("document.FormA.PROJECT.options[i] = new Option(key[num][i]);")
Response.Write("}")
Response.Write("}")
Response.Write("</Script>")

rs.Close
Set rs = Nothing

以上為使用SQL展現動態二階的方式,並且為兩個不同的table,


本篇文章發表於2001-04-24 00:00
目前尚無任何回覆
   

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