如何实现数据联动

panzerchengss 2002-07-22 10:50:49
我最近在编程当中想实现以下效果,当选择一个数据项时,另外一个数据框里的数据将根据所选择数据项的条件列出,比如在第一个选择框里选择一个单位后,该单位所属部门将在第二个选择框里被选择出来。
以下是源代码,但是却出现错误,请教哪儿写错了,另外如果有更简单的,能贴出来吗,高分相送
...全文
35 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
肄若芸 2002-07-22
http://cn7317.www1.cn4e.com/look.txt
我特意找的哦~~~~~:)
回复
panzerchengss 2002-07-22
谢谢,有没有和数据库联动的代码
回复
肄若芸 2002-07-22
代码太多,我看不下去,原理是
用户事件触发js :document.all[name].value 修改值属性
回复
apple749769 2002-07-22
我给你一个例子,以供参考:

<html>
<HEAD>
<title>例子</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<!--代码部分-->
<script language="javascript">
var selects=new Array(new Array(new Option("粮食","粮食"),new Option("油料","油料"), new Option("棉麻烟","棉麻烟"), new Option("蔬菜","蔬菜"),
new Option("水果","水果"),
new Option("水产品","水产品"),
new Option("茶叶","茶叶"),
new Option("副食品","副食品"),
new Option("其它","其它")),
new Array(new Option("农药","农药"),
new Option("化肥","化肥"),
new Option("种子","种子"),
new Option("农机","农机"),
new Option("其它","其它")),
new Array(new Option("原材","原材"),
new Option("种苗","种苗"),
new Option("花卉","花卉"),
new Option("制品","制品"),
new Option("器械","机械"),
new Option("其它","其它")),
new Array( new Option("畜药","畜药"),
new Option("禽药","禽药"),
new Option("鱼药","鱼药"),
new Option("中药材","中药材"),
new Option("其它","其它")));

function chsel()
{
document.f.second.options.length=0;
if(document.f.master.value=="农副")
k=0;
if(document.f.master.value=="农资")
k=1;
if(document.f.master.value=="林水")
k=2;
if(document.f.master.value=="药材")
k=3;
for(var i=0;i<selects[k].length;i++)
document.f.second.add(selects[k][i]);
}
</script>
<!-- 代码部分-->

</head>

<body topmargin="0" leftmargin="0" marginweight="0" marginheight="0" bgcolor="#0099FF" oncontextmenu="return false;"><p> </p>
<P align=center>
<form name=f>
<!-- 代码部分 -->
<SELECT name=master onchange="chsel();">
<Option value="农副">农副</Option>
<Option value="农资">农资</Option>
<Option value="林水">林水</Option>
<Option value="药材">药材</Option>
</SELECT>
<SELECT name=second>
<Option value="粮食">粮食</Option>
<Option value="油料">油料</Option>
<Option value="棉麻烟">棉麻烟</Option>
<Option value="蔬菜">蔬菜</Option>
<Option value="水果">水果</Option>
<Option value="水产品">水产品</Option>
<Option value="茶叶">茶叶</Option>
<Option value="副食品">副食品</Option>
<Option value="其它">其它</Option>
</SELECT>
<!--代码部分-->
</form>
</p>
</center>
</body>
</html>
回复
panzerchengss 2002-07-22
<form name=f1 METHOD="POST">
<%
OpenDB objConn, "xxxx"
Set RSClass = objConn.Execute("SELECT * FROM class Order by fldClass")
If RSClass.EOF Then
Response.Write "噢,没有记录!<BR>"
Else
Response.Write "<SELECT NAME=""class"" style=""FONT-SIZE: 9pt"" SIZE=10"
" ONCHANGE=""classselected(this);"" >"
sJavaScript = "function classselected(elem){" &_
vbCrlf
"for (var i = document.f1.sort.options.length; i >= 0; i--){"
"document.f1.sort.options[i] = null;"
vbCrlf
Do Until RSClass.EOF
If sLastClass <> RSClass("fldClass") Then
sLastClass = RSClass("fldClass")
Response.Write "<OPTION VALUE=" & RSClass("fldID") & ">" & sLastClass & "</OPTION>"
sJavaScript = sJavaScript & "}"
"if (elem.options[elem.selectedIndex].value=="
RSClass("fldID") & "){"
End If
sJavaScript = sJavaScript
"document.f1.sort.options[document."
"f1.sort.options.length] = new Option('"
RSClass("fldSort") & "','" & RSClass("fldID") & "');"
vbCrlf
RSClass.MoveNext
Loop

Response.Write "</SELECT>"
Response.Write "<SELECT NAME=""sort"" style=""FONT-SIZE: 9pt"" SIZE=10>"
Response.Write "<OPTION>请选择</OPTION>"
Response.Write "</SELECT>"
 
sJavaScript = sJavaScript & "}" & "}"

Response.Write "<SCR" & "IPT LANGUAGE=""JavaScript"">"
Response.Write sJavaScript & "</SCR" & "IPT>"

End If
RSClass.Close
Set RSClass = Nothing
%>
</form>
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告