作者:shocknet
index.asp
'jscript_city.asp
db1.mdb
'-------------------------------------------------
福建厦门思明黄厝曾厝桉村
福建泉州丰泽西湖水头村
如上面的五级转成数据库为:
'-------------------------------
idfiled1filed2filed3
100福建
211厦门
311泉州
422思明
534黄厝
645曾厝桉村
723丰泽
837西湖
948水头村
'-------------------------------------------------
数据库说明:
id自动编号
filed1下拉菜单列表的等级(看级数。可以设置它的精度。是数字类型)
filed2上一级的id号(用长整型吧)
filed3这个就不用说了吧(文件。长度自己看情况)
本程序在IIS4+WIN2000P+ACCESS2000下通过。
index.asp
程序代码: |
<html>
<head> <title></title> <metacontent="text/html;charset=gb2312"http-equiv="content-type"> <styletype="text/css"><!-- FONT{font-size:12px} TD{font-size:12px} A{color:#333399} A:hover{color:#FF6600} --></style> <scriptlanguage="JavaScript"type="text/JavaScript"><!-- functionfunOnload(){ document.all.list_file.src="jscript_city.asp?base=0&sele=0-&elem=Select01"; } //pBase级数,以0基, //pSele是<option的value值 //pEle是下一级的表单名字 functionchgSelect(pBase,pSele,pElem){ //当改变了一个列表之后。清除以后的列表的值。 for(i=parseInt(pElem.replace("Select",""));i<=5;i++){ vartmp="000"+i; varpElem1=eval("document.Form1.Select"+tmp.substr(tmp.length-2)); pElem1.length=1; pElem1.selectedIndex=0; } //JS用ASP得到数据库的数据来更新下级列表 document.all.list_file.src="jscript_city.asp?base="+pBase+"&sele="+pSele+"&elem="+pElem; } //--></script> <scriptid="list_file"language="JavaScript"type="text/JavaScript"src=""></script> </head> <bodybgcolor="#FFFFFF"leftmargin="0"topmargin="2"text="#333333"onload="funOnload();"> <formname="Form1"> <selectname="Select01"onchange="chgSelect(1,this.options[this.selectedIndex].value,'Select02')"> <optionvalue="">省...</option> </select> <selectname="Select02"onchange="chgSelect(2,this.options[this.selectedIndex].value,'Select03')"> <optionvalue="">市...</option> </select> <selectname="Select03"onchange="chgSelect(3,this.options[this.selectedIndex].value,'Select04')"> <optionvalue="">县...</option> </select> <selectname="Select04"onchange="chgSelect(4,this.options[this.selectedIndex].value,'Select05')"> <optionvalue="">乡...</option> </select> <selectname="Select05"> <optionvalue="">村...</option> </select> </form> </body></html> |
'jscript_city.asp
程序代码: |
<%
'varBase下拉菜单等级 'varSele所选择下拉菜单项的数据库ID 'varElem下一级的表单名称 varBase=Request.QueryString("base") varSele=Left(Request.QueryString("sele"),InStr(Request.QueryString("sele"),"-")-1) varElem=Request.QueryString("elem") varDistName="" varAutoID="" SetconDB=Server.CreateObject("ADODB.CONNECTION") conDB.Open"Driver={MicrosoftAccessDriver(*.mdb)};DBQ="&Server.Mappath("db1.mdb") sqlCommand="select*fromtable1wherefiled1="&varBase&"andfiled2="&varSele SetrsRecord=conDB.Execute(sqlCommand) WhileNotrsRecord.eof varDistName=varDistName&chr(34)&rsRecord("filed3")&chr(34) varAutoID=varAutoID&chr(34)&rsRecord("id")&chr(34) rsRecord.movenext IfNotrsRecord.EofThen varDistName=varDistName&"," varAutoID=varAutoID&"," EndIf Wend Response.Write("varvarDistName=newArray("&varDistName&")"&vbcrlf) Response.Write("varvarAutoID=newArray("&varAutoID&")"&vbcrlf) Response.Write("varvarElem=eval("&chr(34)&"document.Form1."&varElem&chr(34)&")"&vbcrlf) Response.Write("varElem.length=varDistName.length+1;"&vbcrlf) Response.Write("for(vari=0;i<varDistName.length;i++){"&vbcrlf) Response.Write("varElem.options[i+1].text=varDistName;"&vbcrlf) Response.Write("varElem.options[i+1].value=varAutoID+'-'+varDistName;"&vbcrlf) Response.Write("}"&vbcrlf) Response.Write("varElem.selectedIndex=0;"&vbcrlf) %> |
db1.mdb
'-------------------------------------------------
福建厦门思明黄厝曾厝桉村
福建泉州丰泽西湖水头村
如上面的五级转成数据库为:
'-------------------------------
idfiled1filed2filed3
100福建
211厦门
311泉州
422思明
534黄厝
645曾厝桉村
723丰泽
837西湖
948水头村
'-------------------------------------------------
数据库说明:
id自动编号
filed1下拉菜单列表的等级(看级数。可以设置它的精度。是数字类型)
filed2上一级的id号(用长整型吧)
filed3这个就不用说了吧(文件。长度自己看情况)
本程序在IIS4+WIN2000P+ACCESS2000下通过。