用两个下拉列表框,一个是省份,另一个出现此省的地区,选省份时出现相应的地区,有哪些方法实现。

xupc 2001-07-23 08:18:37
加精
...全文
257 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xupc 2001-07-23
我看了下:
http://java2000.wol.com.cn/index.shtm 这有
[NEW 2 List Dropdown Menu Script - 关联菜单]
但我需要从数据库中选择出来,我不懂java。
有没什么别的方法
回复
brain_wiser 2001-07-23
这很简单的:
首先得到“省份“表单的内容,用查询冲数据库中找出相应的“地区“,作为“地区“下拉框的
<option>项就可以了。


<select>
<%
do while not rs.eof
%>
<option name="" value="<%=rs("area")%>" ><%=rs("area")%></option>
<%
rs.movenext
loop
%>
</select>
回复
sundna 2001-07-23
用JAVA
http://java2000.wol.com.cn/index.shtm 这有
[NEW 2 List Dropdown Menu Script - 关联菜单]
回复
gq 2001-07-23
我贴了三,四回了。找一下吧。太多了。。。
回复
孟子E章 2001-07-23
http://www.csdn.net/expert/topicview1.asp

到javascript论坛搜索一下,有好多关于这方面的
回复
biggo 2001-07-23
很多方法!
你可参考www.pconline.com.cn中的今日报价中的产品列表,它就是这么做的!
回复
gq 2001-07-23


专栏:ASP 文章编号:1520 文章类别: 原创 作者: 钢铁工人 加贴时间:2000-11-2 11:01:34

下拉框连动的小例子(数据库版)

关键词:ASP

ASP文件:
<%@ Language=VBScript %>
<%Option Explicit%>
<html>
<head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
dim conn
dim rs
dim sql
dim count
dim rs1
dim sql1


set conn = server.CreateObject ("adodb.connection")
conn.Open "test","sa",""


sql = "select * from district order by locationid asc"
set rs = conn.execute(sql)
%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("districtname"))%>","<%= trim(rs("locationid"))%>","<%= trim(rs("districtid"))%>");
<%
count = count + 1
rs.movenext
loop
rs.close
set rs=nothing
%>
onecount=<%=count%>;

function changelocation(locationid)
{
document.myform.smalllocation.length = 0;

var locationid=locationid;
var i;
document.myform.smalllocation.options[0] = new Option('====所有地区====','');
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[i][0], subcat[i][2]);
}
}

}
</script>
</head>
<body>
<form name="myform" method="post">
<select name="biglocation" onChange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)">
<%

sql1 = "select * from location order by locationname asc"
set rs1 = conn.Execute (sql1)
do while not rs1.eof
%>
<option value="<%=trim(rs1("locationid"))%>"><%=trim(rs1("locationname"))%></option>
<%
rs1.movenext
loop
rs1.close
set rs1 = nothing
conn.Close
set conn = nothing
%>
</select>
<select name="smalllocation">
<option selected value="">==所有地区==</option>
</select>
</form>
<script LANGUAGE="javascript">
changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value);
</script>
</body>
</html>


数据库:
create table location
(

locationid char(2) not null primary key,
locationname char(50) not null

)


create table district
(

districtid char(3) not null primary key,
districtname char(50) not null,
locationid char(2) not null
)



--------------------------------------------------------------------------------
回复
tonnycncn 2001-07-23
源程序:
<HTML><HEAD><TITLEASP技术</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="../style.css" rel=stylesheet>
<META content="Microsoft FrontPage 4.0" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff topMargin=2 marginheight="4">
<CENTER>
</CENTER>
<CENTER>
<TABLE cellSpacing=0 cellPadding=0 width=755 border=0>
<TBODY>
<TR vAlign=top>
<TD width=755>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="76%" valign="top">
<table border="0" width="100%" cellspacing="1">
<tr>
<td colSpan=4 width="100%" align=center>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();

subcat[0] = new Array("ASP基础教程","1","1");

subcat[1] = new Array("ASP WEB服务器IIS","1","2");

subcat[2] = new Array("ASP网页设计工具FPAGE","1","3");

subcat[3] = new Array("开发工具VISUAL DEV","1","4");

subcat[4] = new Array("VBSCRIPT语言","1","5");

subcat[5] = new Array("ASPFAQ","2","6");

subcat[6] = new Array("ASP组件","2","7");

subcat[7] = new Array("ASP文摘","2","8");

subcat[8] = new Array("ASP实例","2","9");

subcat[9] = new Array("ASP安全","2","10");

subcat[10] = new Array("PHP教程","3","11");

subcat[11] = new Array("PHPFAQ","3","12");

subcat[12] = new Array("PHP文摘","3","13");

subcat[13] = new Array("PHP实例","3","14");

subcat[14] = new Array("PHP安全","3","15");

subcat[15] = new Array("PHP工具","3","16");

subcat[16] = new Array("数据库教程","5","17");

subcat[17] = new Array("数据库问题","5","18");

subcat[18] = new Array("数据库文摘","5","19");

subcat[19] = new Array("数据库安全","5","20");

subcat[20] = new Array("JSP教程","4","21");

subcat[21] = new Array("JSP文摘","4","22");

subcat[22] = new Array("JSP实例","4","23");

subcat[23] = new Array("JSP安全","4","24");

subcat[24] = new Array("JSP工具","4","25");

subcat[25] = new Array("JSPFAQ","4","26");

subcat[26] = new Array("精品子程序","2","27");

subcat[27] = new Array("ASP.NET","2","28");

onecount=28;

function changelocation(locationid)
{
document.myform.Nclassid.length = 0;

var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.Nclassid.options[document.myform.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}

}
</script>
<form method="post" name="myform" action="ru_query.asp">
文章搜索:
<select name="action" size="1">
<option value="title">文章标题</option>
</select>
<select name="classid" onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)" size="1">
<option selected value="">未指定条件</option>
<option value="1">ASP基础教程</option>
<option value="2">ASP技术</option>
<option value="3">PHP技术</option>
<option value="4">JSP技术</option>
<option value="5">数据库</option>
</select>
<select name="Nclassid">
<option selected value="">未指定条件</option>
</select>
<input type="text" name="keyword" class=smallinput size=10 value="关键字" maxlength="50">
<input type="submit" name="Submit" value="搜索">
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</TD>
</TR>
</TBODY>
</TABLE>
</CENTER>
</BODY></HTML>
回复
xupc 2001-07-23
我不懂java呀,烦您老贴一下吧。
回复
gq 2001-07-23
<html>
<head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script LANGUAGE="javascript">
<!--
var onecount;
onecount=0;

subcat = new Array();
subcat[0] = new Array("徐汇区","01","001");
subcat[1] = new Array("嘉定区","01","002");
subcat[2] = new Array("黄浦区","01","003");
subcat[3] = new Array("南昌市","02","004");
subcat[4] = new Array("九江市","02","005");
subcat[5] = new Array("上饶市","02","006");

onecount=6;

function changelocation(locationid)
{
document.myform.smalllocation.length = 0;

var locationid=locationid;
var i;
document.myform.smalllocation.options[0] = new Option('====所有地区====','');
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[i][0], subcat[i][2]);
}
}

}

//-->
</script>
</head>
<body>
<form name="myform" method="post">
<select name="biglocation" onChange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)">
<option value="01" selected>上海</option>
<option value="02">江西</option>
</select>
<select name="smalllocation">
<option selected value="">==所有地区==</option>
</select>
</form>
<script LANGUAGE="javascript">
<!--
changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value);
//-->
</script>
</body>
</html>


唉。我在贴一次。。
改为数据库版。兄弟你自己动手了。。呵呵。。
将数据读出。写到数组中去就行了。。
我以前改过。不知道放到那里去了。。。
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2001-07-23 08:18
社区公告
暂无公告