三级下拉框连动的数据库版

'三级下拉框连动
'
'数据库:
'location
'表1 loaction 所在地表
' 字段
' loactionid
' loactionname 名字
'表2 district 所在的地区表
' 字段
' locationid
' districtid
' districtname
'表3 village 所在的县区表
' 字段
' districtid
' villageid
' villagename

1Option Explicit
1<html>
2<head>
3<title>List</title>
4<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>   

dim conn
dim rs
dim sql
dim count
dim rs1
dim sql1
dim rs2
dim sql2
dim count2

set conn=server.createobject("adodb.connection")
conn.open"provider=sqloledb;data source=192.168.0.33;uid=sa;pwd=;database=location;"

sql = "select * from district order by locationid asc"
set rs = conn.execute(sql)

1<script language="JavaScript">   
2var onecount;   
3onecount=0;   
4subcat = new Array();   

count = 0
do while not rs.eof

1subcat[```
2=count
3```] = new Array("```
4= trim(rs("districtname"))
5```","```
6= trim(rs("locationid"))
7```","```
8= trim(rs("districtid"))
9```");   

count = count + 1
rs.movenext
loop
rs.close
set rs=nothing

 1onecount=```
 2=count
 3```;   
 4  
 5function changelocation(locationid)   
 6{   
 7document.myform.smalllocation.length = 0;   
 8  
 9var locationid=locationid;   
10var i;   
11document.myform.smalllocation.options[0] = new Option('==所选城市的地区==','');   
12for (i=0;i < onecount; i++)   
13{   
14if (subcat[i][1] == locationid)   
15{   
16document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[i][0], subcat[i][2]);   
17}   
18}   
19  
20}   
21</script>   
22  
23  

sql2 = "select * from village order by districtid asc"
set rs2 = conn.execute(sql2)

1<script language="JavaScript">   
2var onecount2;   
3onecount2=0;   
4subcat2 = new Array();   

count2 = 0
do while not rs2.eof

1subcat2[```
2=count2
3```] = new Array("```
4= trim(rs2("villagename"))
5```","```
6= trim(rs2("districtid"))
7```","```
8= trim(rs2("villageid"))
9```");   

count2 = count2 + 1
rs2.movenext
loop
rs2.close
set rs2=nothing

 1onecount2=```
 2=count2
 3```;   
 4  
 5function changelocation2(villageid)   
 6{   
 7document.myform.village.length = 0;   
 8  
 9var villageid=villageid;   
10var j;   
11document.myform.village.options[0] = new Option('==所选地区的县区==','');   
12for (j=0;j < onecount2; j++)   
13{   
14if (subcat2[j][1] == villageid)   
15{   
16document.myform.village.options[document.myform.village.length] = new Option(subcat2[j][0], subcat2[j][2]);   
17}   
18}   
19  
20}   
21</script>
22</head>
23<body>
24<form method="post" name="myform">   
25题目:<input name="T2" size="20" type="text"/>   
26  
27来源:<input name="T3" size="20" type="text"/>   
28  
29分类:<select name="biglocation" onchange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)" size="1">
30<option selected="">请选择你所在的省份</option>   

sql1 = "select * from location order by locationname asc"
set rs1 = conn.Execute (sql1)
do while not rs1.eof

1<option ```"="" locationid"))="" value="```
2=trim(rs1(">```
3=trim(rs1("locationname"))
4```</option>   
5  

rs1.movenext
loop
rs1.close
set rs1 = nothing
conn.Close
set conn = nothing

 1</select><select name="smalllocation" onchange="changelocation2(document.myform.smalllocation.options[document.myform.smalllocation.selectedIndex].value)">
 2<option selected="" value="">==所有地区==</option>
 3</select><select name="village" size="1">
 4<option selected="">==所有县区==</option>
 5</select>   
 6  
 7  
 8关键词:<input name="T4" size="20" type="text"/>   
 9  
10内容:<textarea cols="51" name="S1" rows="9"></textarea>
11</form>
12</body>
13</html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus