关于下拉框的问题

ChanMoon 2003-08-18 08:03:30
想要实现这样一个功能:比如说,两个下拉框,第一个是大部门列表,第二个是大部门的小部门,每个大部门下属的小部门是不一样的,所以要在第一个下拉框中选中某个大部门后,下面那个下拉框中的项目就变成相应所属的小部门可供选择。
不知如何实现~
...全文
37 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zscjp 2003-08-19
  • 打赏
  • 举报
回复
<td bgcolor=#efefef height=17 valign="top" width="151"> 选择部门:</td>
<td bgcolor=#efefef height=17 colspan="3" valign=top>

<%
set rs=server.createobject("ADODB.recordset")
set rs1=server.createobject("ADODB.recordset")
exec1="select Dept from H_bumen"
exec2="select Dept,CName from UserInfo_detail"
exec3="select count(*) number from UserInfo_detail" ' 统计有多少
%>
<select name="BuMen" onChange="changelocation(document.myform.BuMen.value)" >
<option >---请选择被授权人所属部门---</option>
<option value="**">**</option>
<option value="**">**</option>
<option value="**">**</option>
</select>
<%
rs.open exec3,Conn,1,3
strNum=rs("number")
dim strarry()
redim strarry(strNum,1)
rs1.open exec2,Conn,1,3

i=0
do while not rs1.EOF and not rs1.bof
strarry(i,0)=rs1("Dept")
strarry(i,1)=rs1("CName")
rs1.movenext
i=i+1
loop
rs.close
rs1.close
set rs=nothing
set rs1=nothing
%>
</td>
</tr>
<tr>

<td bgcolor=#efefef height=42 valign="top" rowspan="3" width="151">选择小部门:
</td>
<td bgcolor=#efefef height=42 width="139" valign=top align=right rowspan="3">
<script language=javascript>
function changelocation(location)
{
var Name=location;
var subcat = new Array();
<%for i=0 to strNum%>
subcat[<%=i%>]=new Array("<%=strarry(i,0)%>","<%=strarry(i,1)%>");
<%next%>
document.myform.a.length = 0; // a 为负责人列表框的名称。
//s2.length=0;
ccc="<%=strNum%>"
for (i=0;i<ccc;i++)
{
if (subcat[i][0]==Name)
{
document.myform.a.options[document.myform.a.length] = new Option(subcat[i][1], subcat[i][1]);
}
}
}
</script>
<select name="a" size="8" multiple style="width:130" ondblclick=move('a','b')>
</select>
</td>
mjwgtm 2003-08-19
  • 打赏
  • 举报
回复
作者:月影飞鸿
从数据库中全部下载到客户段,然后再连动的,页面不会刷新
<!--月影飞鸿2003-05-25 晚-->
<!--#include file = dbconn.asp-->
<body onload =" ChangeProvince(document.all.Province);">
<%
Dim Arr_City

sub CloseRs(rs)
Rs.close
set Rs = nothing
end sub

Sql_All = "Select Id,Name from prover"
set Rs_All = Server.CreateObject ("adodb.recordset")
Rs_All.Open Sql_All,conn,3,1

'动态生成一个内容为省的select
Response.Write "<Select name = Province id = Province onchange = ChangeProvince(this)>"
do while not Rs_All.EOF
%>
<option value = <%=Rs_All("Id")%>><%=Rs_All("Name")%>
<%
Rs_All.MoveNext
loop
Response.Write "</Select>"
'到此第一个select为止

CloseRs(Rs_All)

'在城市表city中选择所有记录。Id:城市Id;CId:省Id;Name:城市的名字。
'然后按照:省Id加上“,”加上城市Id加上“,”加上城市的名字组合成一个字符串;
'如:'1,2,济南',表示:省的Id是1,城市的Id是2,城市的名字是 济南。
'然后每一个类似的字符串作为一个一维数组的一个元素的值。
'如此循环,动态生成了一个数组,每一个下表的值为类似“1,2,济南”的字符串
Sql_City= "select Id,CId,Name from city order by Id"
set Rs_City = server.CreateObject ("adodb.recordset")
Rs_City.Open Sql_City,conn,3,1
count = Rs_City.RecordCount '得到动态数组的元素个数
redim Arr_City(count) '重新初始化动态数组
i = 0
do while not Rs_City.EOF
New_Str = ""
theId = Rs_City("Id") '得到城市Id
theCId = Rs_City("CId") '得到省的Id
theName = Rs_City("Name") '得到城市的名字
New_Str = theCId&","&theId&","&theName '组合成一个字符串
Arr_City(i) = New_Str '给数组赋值
i = i +1
Rs_City.MoveNext
loop

'动态数组的创建到此为止

CloseRs(Rs_City)
Conn.Close
set Conn = Nothing

'然后把上边动态生成的数组Arr_City赋值给javascipt中的一个数组:All_City
Response.Write "<script language = javascript>"
Response.Write " var All_City = new Array("&count&");"
for i = lbound(Arr_City) to ubound(Arr_City)-1
Response.Write "All_City["&i&"] = '"&Arr_City(i)&"';"
next
Response.Write "</script>"
'数组赋值到此为止

'产生一个空的select,用来存放动态生成的城市
%>
<select name = City id = City>
</select>
<% '到此为止 %>

</body>

<script language = javascript>

function ChangeProvince(id)
{
theProvinceId = id.options[id.selectedIndex].value; //得到所选择省的Id

for (j = document.all.City.length;j>=0;j--) //去掉原来城市select中的城市
document.all.City.remove(j);

for (i = 0 ;i<<%=count%>;i++)
{
theCity = All_City[i].split(","); //利用函数split生成一个数组theCity,内容类似为("1","2","济南")
if (theProvinceId == theCity[0])
{
document.all.City.options.add(new Option(theCity[2])); //第二个select动态增加内容
}
}

}

</script>
<script for = window event = onunload>
window.open ("excel.asp");
</script>
mjwgtm 2003-08-19
  • 打赏
  • 举报
回复
数据库名:db.mdb 表名:tableName 字段1:provinceName(你的MAIN)
字段2:cityname(你的SUB)

<body style="font-size:14px">
<center>
<form name=form1 method="POST" action="czcxf.asp">
<script language=javascript>
<%
dim RS,conn
set rs=server.createobject("adodb.recordset")
conn="DBQ=" + server.mappath("db.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.open "SELECT * FROM tableName ORDER BY provinceName DESC",conn,1,1

dim provinceName
dim provinceList
dim cityList
dim cityIndex
cityIndex = 1

do while not RS.eof
if isEmpty(provinceName) then
cityList = cityList & chr(34) & Trim(RS("cityName")) & chr(34) &","
provinceName = Trim(RS("provinceName"))
else
if provinceName<>Trim(RS("provinceName")) then
provinceList = provinceList & chr(34) & provinceName & chr(34) &","
if not isEmpty(cityList) then Response.write "var city"& cityIndex &_
" = ["& Left(cityList, Len(cityList)-1) &"];"& VBCrLf

cityIndex = cityIndex + 1
cityList = ""
end if
provinceName = Trim(RS("provinceName"))
cityList = cityList & chr(34) & Trim(RS("cityName")) & chr(34) &","

end if
RS.movenext
loop

if not isEmpty(cityList) then
Response.write "var city"& cityIndex &" = ["& Left(cityList, Len(cityList)-1) &"];"& VBCrLf
end if
if not isEmpty(provinceName) then
provinceList = provinceList & chr(34) & provinceName & chr(34) &","
Response.write "var provinceName = ["& Left(provinceList, Len(provinceList)-1) &"];"

end if


%>
</script>
<select name=province style="BACKGROUND-COLOR: #FF9900; COLOR: #ffffff; " onChange="cityName(this.selectedIndex)">
<option value="">请选择省名</option>
</select>
<select name=city style="BACKGROUND-COLOR: #FF9900; COLOR: #ffffff;">
<option value="">请选择站名</option>
</select>
<script language=javascript>

function province()
{

var e = document.form1.province;
for (var i=0; i<provinceName.length; i++)
e.options.add(new Option(provinceName[i], provinceName[i]));
}
function cityName(n)
{
var e = document.form1.city;
for (var i=e.options.length; i>0; i--) e.remove(i);
if (n == 0) return;
var a = eval("city"+ n);
for (var i=0; i<a.length; i++) e.options.add(new Option(a[i], a[i]));
}
function window.onload()
{
province();
}
</script>
</form>
</center></body>
</html>
fason 2003-08-18
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1965/1965486.xml?temp=.9098322

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧