<p align="center"> <select size="1" name="D2" onchange="javascript:change(this,form.D1)"> <% sqlstr="select a.b_name b_name,b.b_code b_code from rsv_code a,rsv_cdr b where a.stcd=b.stcd" Set rs=fcpdb.execute(sqlstr) If Not rs.eof And Not rs.bof Then rs.movefirst While Not rs.EOF %> <option value="<%=rs("b_code")%>"><%=TRIM(rs("b_name"))%></option> <% rs.MoveNext Wend End If %> </select> <select size="1" name="D1"> </select> </form> <Script LANGUAGE="JavaScript"> function change(source,target) { if(source.options(source.selectedIndex).value=="") return; target.innerHTML="" var url = '<%=strPathInfo%>XML_Data.asp?b_code=' + source.options(source.selectedIndex).value; //这里传递条件到 XML_Data.asp,XML_Data.asp生成XML的查询结果 var oXMLDoc = new ActiveXObject('MSXML'); oXMLDoc.url = url;
</html> XML_Data.asp ================================= <?xml version="1.0" encoding="gb2312" ?> <St_code_as> <% Dim fcpdb, rs,sqlstr,b_code Set fcpdb=server.createobject("adodb.connection") fcpdb.CursorLocation=3 fcpdb.open "dsn=test;uid=sa;pwd=;" b_code = Request("b_code") sqlstr = "select c.stcd stcd,c.hs_name hs_name from rst_code a,St_cdr b,St_code_a c,St_code_b d where a.hs_code=b.hs_code and b.stcd=c.stcd and c.stcd=d.stcd and d.hs_type='F' and a.b_code=" & b_code Set rs=fcpdb.execute(sqlstr) If Not rs.eof And Not rs.bof Then rs.MoveFirst While Not rs.eof %> <St_code_as id="<%=rs("stcd")%>"><%=rs("hs_name")%></St_code_as> <% rs.MoveNext Wend Else %> <St_code_as id="无数据">无数据</St_code_as> <% End If %> </St_code_as>
<html><head><script>
function check()
{
if(f1.d1.options[0].selected)
{
f1.d2.length=0 f1.d2.options.add(new Option("白菜","白菜"))
f1.d2.options.add(new Option("萝卜","萝卜"))
}
else if(f1.d1.options[1].selected)
{
f1.d2.length=0
f1.d2.options.add(new Option("苹果","苹果"))
f1.d2.options.add(new Option("桃","桃")) }}
</script>
</head><body><form name="f1" method="POST" action="--WEBBOT-SELF--">
<p><select size="1" name="d1" onchange="check()">
<option>蔬菜</option>
<option>水果</option>
</select><select size="1" name="d2">
</select></p>
</form></body></html>
用XML,就是wangyiyun0119(wangyy) 说的原理============================
<html>
<head>
<title>New Page 2</title>
</head>
<body bgcolor="#F4FAFF" leftmargin="0">
<%
strPathInfo = Request.ServerVariables("PATH_INFO")
strPathInfo = "http://" & Request.ServerVariables("SERVER_NAME") & Left(strPathInfo,InstrRev(strPathInfo,"/"))
%>
<%
'================================================================
'这里是我的连接数据库的代码,你把他换成你的就行了
Dim fcpdb, rs,sqlstr
Set fcpdb=server.createobject("adodb.connection")
fcpdb.CursorLocation=3
fcpdb.open "dsn=test;uid=sa;pwd=;"
'================================================================
%>
<form method="post" target="mn" action="result.asp" name=form >
<p align="center">
<select size="1" name="D2" onchange="javascript:change(this,form.D1)">
<%
sqlstr="select a.b_name b_name,b.b_code b_code from rsv_code a,rsv_cdr b where a.stcd=b.stcd"
Set rs=fcpdb.execute(sqlstr)
If Not rs.eof And Not rs.bof Then
rs.movefirst
While Not rs.EOF
%>
<option value="<%=rs("b_code")%>"><%=TRIM(rs("b_name"))%></option>
<%
rs.MoveNext
Wend
End If
%>
</select>
<select size="1" name="D1">
</select>
</form>
<Script LANGUAGE="JavaScript">
function change(source,target)
{ if(source.options(source.selectedIndex).value=="")
return;
target.innerHTML=""
var url = '<%=strPathInfo%>XML_Data.asp?b_code=' + source.options(source.selectedIndex).value; //这里传递条件到 XML_Data.asp,XML_Data.asp生成XML的查询结果
var oXMLDoc = new ActiveXObject('MSXML');
oXMLDoc.url = url;
var oRoot=oXMLDoc.root;
if(oRoot.children != null)
{
for(var i=0;i<oRoot.children.length;++i)
{
oItem = oRoot.children.item(i);
sName = oItem.text;
sValue = oItem.getAttribute("id");
var oOption = document.createElement('OPTION');
oOption.text = sName;
oOption.value = sValue;
target.options.add(oOption);
}
}
}
window.attachEvent("onload",new Function("change(form.D2,form.D1)"))
</Script>
</body>
</html>
XML_Data.asp
=================================
<?xml version="1.0" encoding="gb2312" ?>
<St_code_as>
<%
Dim fcpdb, rs,sqlstr,b_code
Set fcpdb=server.createobject("adodb.connection")
fcpdb.CursorLocation=3
fcpdb.open "dsn=test;uid=sa;pwd=;"
b_code = Request("b_code")
sqlstr = "select c.stcd stcd,c.hs_name hs_name from rst_code a,St_cdr b,St_code_a c,St_code_b d where a.hs_code=b.hs_code and b.stcd=c.stcd and c.stcd=d.stcd and d.hs_type='F' and a.b_code=" & b_code
Set rs=fcpdb.execute(sqlstr)
If Not rs.eof And Not rs.bof Then
rs.MoveFirst
While Not rs.eof
%>
<St_code_as id="<%=rs("stcd")%>"><%=rs("hs_name")%></St_code_as>
<%
rs.MoveNext
Wend
Else
%>
<St_code_as id="无数据">无数据</St_code_as>
<%
End If
%>
</St_code_as>
用xmlhttp就不用刷新页面了