如何实现连环选择?

chjin 2008-07-31 03:30:07
比如第一个选择框中选择国家,然后查询数据库,在第二个选择框中列出该国家的所有省,然后选择某一个省,在第三个选择框中列出该省的所有城市

谢谢.
...全文
87 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chjin 2008-07-31
  • 打赏
  • 举报
回复
谢谢各位.
egg_server 2008-07-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 windwl 的回复:]
搜索三级连动
有很多现成的例子和代码
[/Quote]
半山闲人 2008-07-31
  • 打赏
  • 举报
回复
去找现成的吧,这个程序都被人问烂了,三级联动!
cimzzxiang 2008-07-31
  • 打赏
  • 举报
回复
同意楼上的
jacklinchen 2008-07-31
  • 打赏
  • 举报
回复
三级连动啊,我这是动态的从数据库取值的。

<script language="javascript">
<%
'''取市别列表
dim rstw,sqltw
sqltw=""
sqltw="select * from tbTownInfo order by ProvinceID,TownID"
set rstw=server.CreateObject("adodb.recordset")
rstw.Open sqltw,conn,1,1

'''取县别列表
dim rscy,rscy3,rscy4,sqlcy
sqlcy=""
sqlcy="select * from tbCountyInfo where TownID in (select TownID from tbTownInfo where ProvinceID<16) order by TownID,CountyID"
set rscy=server.CreateObject("adodb.recordset")
rscy.CursorLocation=3
rscy.Open sqlcy,conn,1,3

sqlcy=""
sqlcy="select * from tbCountyInfo where TownID in (select TownID from tbTownInfo where ProvinceID>15 and ProvinceID<26) order by TownID,CountyID"
set rscy3=server.CreateObject("adodb.recordset")
rscy3.CursorLocation=3
rscy3.Open sqlcy,conn,1,3

sqlcy=""
sqlcy="select * from tbCountyInfo where TownID in (select TownID from tbTownInfo where ProvinceID>25) order by TownID,CountyID"
set rscy4=server.CreateObject("adodb.recordset")
rscy4.CursorLocation=3
rscy4.Open sqlcy,conn,1,3

%>

////将市别放入数组
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
if rstw.recordcount>0 then
do while not rstw.eof
%>
subcat[<%=count%>] = new Array("<%=rstw("ProvinceID")%>","<%=trim(rstw("TownCnName"))%>","<%=rstw("TownID")%>","<%=trim(rstw("TownEnName"))%>");
<%
count = count + 1
rstw.movenext
loop
else
count=-1
end if
rstw.close
set rstw=nothing
%>
onecount=<%=count%>;


////将县别放入数组
var onecount2;
onecount2=0;
subcat2 = new Array();
<%
count2 = 0
if rscy.recordcount>0 then
do while not rscy.eof
%>
subcat2[<%=count2%>] = new Array("<%=rscy("TownID")%>","<%=trim(rscy("CountyCnName"))%>","<%=rscy("CountyID")%>","<%=trim(rscy("CountyEnName"))%>");
<%
count2 = count2 + 1
rscy.movenext
loop
else
count2=-1
end if
rscy.close
set rscy=nothing
%>
onecount2=<%=count2%>;

var onecount3;
onecount3=0;
subcat3 = new Array();
<%
count3 = 0
if rscy3.recordcount>0 then
do while not rscy3.eof
%>
subcat3[<%=count3%>] = new Array("<%=rscy3("TownID")%>","<%=trim(rscy3("CountyCnName"))%>","<%=rscy3("CountyID")%>","<%=trim(rscy3("CountyEnName"))%>");
<%
count3 = count3 + 1
rscy3.movenext
loop
else
count3=-1
end if
rscy3.close
set rscy3=nothing
%>
onecount3=<%=count3%>;

var onecount4;
onecount4=0;
subcat4 = new Array();
<%
count4 = 0
if rscy4.recordcount>0 then
do while not rscy4.eof
%>
subcat4[<%=count4%>] = new Array("<%=rscy4("TownID")%>","<%=trim(rscy4("CountyCnName"))%>","<%=rscy4("CountyID")%>","<%=trim(rscy4("CountyEnName"))%>");
<%
count4 = count4 + 1
rscy4.movenext
loop
else
count4=-1
end if
rscy4.close
set rscy4=nothing
%>
onecount4=<%=count4%>;
</script>

<script language="javascript">

function changeposition1(locationid)
{
if(locationid<4&&locationid>0)
{
frmsrh.TownID.style.visibility="hidden";
frmsrh.CountyID.style.visibility="hidden";
}
else
{
if(locationid>0)
{
frmsrh.TownID.style.visibility="visible";
frmsrh.CountyID.style.visibility="visible";

//通过省份选择地级市
document.frmsrh.TownID.length = 0;
var locationid=locationid;
var i;
var j;

document.frmsrh.TownID.options[0] = new Option('地级市','');
if (i<0)
{
document.frmsrh.TownID.options[document.frmsrh.TownID.length] = new Option('地级市','0');
}
else
{
for (i=0;i < onecount; i++)
{
if (subcat[i][0] == locationid)
{
document.frmsrh.TownID.options[document.frmsrh.TownID.length] = new Option(subcat[i][1],subcat[i][2]);
}
}
document.frmsrh.TownID.options[0].selected=true;
}
changeposition2(document.frmsrh.TownID.options[0].value);
}
else
{
frmsrh.TownID.style.visibility="visible";
frmsrh.CountyID.style.visibility="visible";
document.frmsrh.TownID.length = 0;
document.frmsrh.TownID.options[0] = new Option('地级市','');
document.frmsrh.CountyID.length = 0;
document.frmsrh.CountyID.options[0] = new Option('县市选择','');
}
}
}

function changeposition2(locationid)
{
var flagc;
flagc=0

//通过地级市选择县别
document.frmsrh.CountyID.length = 0;
var locationid=locationid;
var i,cid;
cid=0
document.frmsrh.CountyID.options[0] = new Option('县市选择','');
if (i<0)
{
document.frmsrh.CountyID.options[document.frmsrh.CountyID.length] = new Option('县市选择','0');
}
else
{
for (i=0;i < onecount2; i++)
{
if (subcat2[i][0] == locationid)
{
//if(document.frmsrh.CountyID.length==1){cid=i;}
document.frmsrh.CountyID.options[document.frmsrh.CountyID.length] = new Option(subcat2[i][1],subcat2[i][2]);

}
}


for (i=0;i < onecount3; i++)
{
if (subcat3[i][0] == locationid)
{
//if(document.frmsrh.CountyID.length==1){cid=i;}
document.frmsrh.CountyID.options[document.frmsrh.CountyID.length] = new Option(subcat3[i][1],subcat3[i][2]);
}
}

for (i=0;i < onecount4; i++)
{
if (subcat4[i][0] == locationid)
{
//if(document.frmsrh.CountyID.length==1){cid=i;}
document.frmsrh.CountyID.options[document.frmsrh.CountyID.length] = new Option(subcat4[i][1],subcat4[i][2]);
}
}

document.frmsrh.CountyID.options[0].selected=true;
}
}
</script>

<form method="POST" id="frmsrh" name="frmsrh" action="NewsSrh.asp?action=company" onSubmit="javascript:return chkfrm();" target=_blank>
<select name="ProvinceID" onChange="javascript:changeposition1(document.frmsrh.ProvinceID.options[document.frmsrh.ProvinceID.selectedIndex].value)">
<option value="" selected>省份选择</option>
<%
dim rspr,sqlpr
sqlpr=""
sqlpr="select * from tbProvinceInfo order by ProvinceID"
set rspr=server.CreateObject("adodb.recordset")
rspr.Open sqlpr,conn,1,1
if rspr.RecordCount > 0then
do while not rspr.EOF
Response.Write "<option value='"&rspr("ProvinceID")&"'>"&rspr("ProvinceCnName")&"</option>"
rspr.MoveNext
loop
end if
rspr.Close
%>
</select>
<select name="TownID" onChange="javascript:changeposition2(document.frmsrh.TownID.options[document.frmsrh.TownID.selectedIndex].value)" ID="Select5">
<option value="">地级市</option>
</select>
<select name="CountyID">
<option value="">县市选择</option>
</select>
</form>
sy_binbin 2008-07-31
  • 打赏
  • 举报
回复
三级联动啊!
windwl 2008-07-31
  • 打赏
  • 举报
回复
搜索三级连动
有很多现成的例子和代码

28,391

社区成员

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

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