asp取下拉框值来做搜索条件,要在当前页面执行
商品2级分类(大类和小类)下拉框,要求:选择大类下拉框的某个值后,页面下面的商品显示列表能根据选择的商品大类类别来显示。希望用asp+ajax来操作,用js的话刷新页面大...
商品2级分类(大类和小类)下拉框,要求:选择大类下拉框的某个值后,页面下面的商品显示列表能根据选择的商品大类类别来显示。希望用asp+ajax来操作,用js的话刷新页面大类下拉框会作初始化的,所以不想用。
不知道我说的清不清楚,不清楚的请提出。
老大们帮帮忙,贴完全代码,能用的在追加100分,谢谢!
补充一下:下拉框的2级联动我已做好,现在就是需要在大类下拉框中选取某商品大类(小类已自动关联)后,商品显示列表会根据已选择的商品大类来列出。大概样子如下:
<table width="490" height="123" >
<tr>
<td height="37"><select size="1" name="dalei">
<option value="CPU">CPU</option>
</select> <select size="1" name="D2">
<option value="INTEL">INTEL</option>
</select> 注释:左面的2级下拉框已联动 </td>
</tr>
<tr>
<td height="77"><hr size="1">
<table width="490" height="62" >
<tr>
<td height="24" width="50" >ID</td>
<td height="24" width="193" >商品名称</td>
<td height="24" width="217" >供货商</td>
</tr>
<tr>
<td height="20" width="50" >1</td>
<td height="20" width="193" >llll</td>
<td height="20" width="217" > </td>
</tr>
</table>
</td>
</tr>
</table> 展开
不知道我说的清不清楚,不清楚的请提出。
老大们帮帮忙,贴完全代码,能用的在追加100分,谢谢!
补充一下:下拉框的2级联动我已做好,现在就是需要在大类下拉框中选取某商品大类(小类已自动关联)后,商品显示列表会根据已选择的商品大类来列出。大概样子如下:
<table width="490" height="123" >
<tr>
<td height="37"><select size="1" name="dalei">
<option value="CPU">CPU</option>
</select> <select size="1" name="D2">
<option value="INTEL">INTEL</option>
</select> 注释:左面的2级下拉框已联动 </td>
</tr>
<tr>
<td height="77"><hr size="1">
<table width="490" height="62" >
<tr>
<td height="24" width="50" >ID</td>
<td height="24" width="193" >商品名称</td>
<td height="24" width="217" >供货商</td>
</tr>
<tr>
<td height="20" width="50" >1</td>
<td height="20" width="193" >llll</td>
<td height="20" width="217" > </td>
</tr>
</table>
</td>
</tr>
</table> 展开
1个回答
展开全部
以下只做参考,详细使用时,还需扒清要自己多研究
文件列表:
js.js
---------------------------------------------------------
function createxmlhttp()
{
xmlhttpobj = false;
try{
xmlhttpobj = new XMLHttpRequest;
}catch(e){
try{
xmlhttpobj=new ActiveXObject("MSXML2.XMLHTTP");
}catch(e2){
try{
xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e3){
xmlhttpobj = false;
}
}
}
return xmlhttpobj;
}
function getsubcategory(bigclassid){
if(bigclassid==0){
document.getElementById("subclass").innerHTML="<select name='smallclassid'><option value='0' selected>选择二级分类</option></select>";
return;
};
var xmlhttpobj = createxmlhttp();
if(xmlhttpobj){//如果创建对象xmlhttpobj成功
xmlhttpobj.open('get',"getsubcategory.asp?bigclassid="+bigclassid+"&number="+Math.random(),true);//get方法 加个随机数。
xmlhttpobj.send(null);
xmlhttpobj.onreadystatechange=function(){//客户端监控函数
if(xmlhttpobj.readystate==4){//服务器处理请求完成
if(xmlhttpobj.status==200){
//alert('ok');
var html = xmlhttpobj.responseText;//获得返回值
document.getElementById("subclass").innerHTML=html;
}else{
document.getElementById("subclass").innerHTML="对不起,您请春薯前求的页面有问题...";
}
}else{
document.getElementById("subclass").innerHTML="加载中,手神请梢候...";//服务器处理中
}
}
}
}
----------------------------------------------------------------
index.asp
-----------------------------------------------------------------
<!--#include file="iconn.asp"-->
<script language="javascript" src="js.js"></script>
<%
Set afeng = Conn.Execute("select bigclassid,bigclassname from bigclass")
%>
<form id="form1" name="form1" method="post" action="">
<div id="bigclass" style="float:left">
<select name="select" onchange="getsubcategory(this.value);">
<option value="0">选择一级分类</option>
<%If Not afeng.Eof then
Do While Not afeng.Eof
bigclassid= afeng("bigclassid")
bigclassname = afeng("bigclassname")%>
<option value="<%=bigclassid%>"><%=bigclassname%></option>
<%afeng.Movenext
Loop
End If
afeng.Close
Set afeng = Nothing
Conn.Close
Set Conn = Nothing%>
</select>
</div>
<div id="subclass" style="float:left"><select name="select2">
<option value="0">选择二级分类</option>
</select>
</div>
</form>
--------------------------------------------------------------------
getsubcategory.asp
--------------------------------------------------------------------
<%
Response.Charset="GB2312"
bigclassid=safe(request.QueryString("bigclassid"))
If bigclassid<>"" Then
Set Re=New RegExp
Re.IgnoreCase=true
Re.Global=false
Re.Pattern = "^[0-9]{1,3}$"
If Not Re.Test(bigclassid) Then
Response.Write "非法参数"
Response.End
End If%>
<!--#include file="iconn.asp"-->
<%On error Resume Next
set p = conn.execute("select * from smallclass where bigclassid="&bigclassid&"")
If Err Then
Err.Clear
Response.Write "查询出错"
Response.End
End If
If Not p.Eof Then
html = "<select name='smallclassid'>"&vbnewline
Do While Not p.Eof
html = html&"<option value='"&p("smallclassid")&"'>"&p("smallclassname")&"</option>"&vbnewline
p.Movenext
Loop
html = html&"</select>"
Else
html = "<select name='smallclassid'><option value='0' selected>暂无小类</option></select>"
End If
p.Close
Set p = Nothing
Conn.Close
Set Conn = Nothing
Response.write html
html = ""
End If
%>
文件列表:
js.js
---------------------------------------------------------
function createxmlhttp()
{
xmlhttpobj = false;
try{
xmlhttpobj = new XMLHttpRequest;
}catch(e){
try{
xmlhttpobj=new ActiveXObject("MSXML2.XMLHTTP");
}catch(e2){
try{
xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e3){
xmlhttpobj = false;
}
}
}
return xmlhttpobj;
}
function getsubcategory(bigclassid){
if(bigclassid==0){
document.getElementById("subclass").innerHTML="<select name='smallclassid'><option value='0' selected>选择二级分类</option></select>";
return;
};
var xmlhttpobj = createxmlhttp();
if(xmlhttpobj){//如果创建对象xmlhttpobj成功
xmlhttpobj.open('get',"getsubcategory.asp?bigclassid="+bigclassid+"&number="+Math.random(),true);//get方法 加个随机数。
xmlhttpobj.send(null);
xmlhttpobj.onreadystatechange=function(){//客户端监控函数
if(xmlhttpobj.readystate==4){//服务器处理请求完成
if(xmlhttpobj.status==200){
//alert('ok');
var html = xmlhttpobj.responseText;//获得返回值
document.getElementById("subclass").innerHTML=html;
}else{
document.getElementById("subclass").innerHTML="对不起,您请春薯前求的页面有问题...";
}
}else{
document.getElementById("subclass").innerHTML="加载中,手神请梢候...";//服务器处理中
}
}
}
}
----------------------------------------------------------------
index.asp
-----------------------------------------------------------------
<!--#include file="iconn.asp"-->
<script language="javascript" src="js.js"></script>
<%
Set afeng = Conn.Execute("select bigclassid,bigclassname from bigclass")
%>
<form id="form1" name="form1" method="post" action="">
<div id="bigclass" style="float:left">
<select name="select" onchange="getsubcategory(this.value);">
<option value="0">选择一级分类</option>
<%If Not afeng.Eof then
Do While Not afeng.Eof
bigclassid= afeng("bigclassid")
bigclassname = afeng("bigclassname")%>
<option value="<%=bigclassid%>"><%=bigclassname%></option>
<%afeng.Movenext
Loop
End If
afeng.Close
Set afeng = Nothing
Conn.Close
Set Conn = Nothing%>
</select>
</div>
<div id="subclass" style="float:left"><select name="select2">
<option value="0">选择二级分类</option>
</select>
</div>
</form>
--------------------------------------------------------------------
getsubcategory.asp
--------------------------------------------------------------------
<%
Response.Charset="GB2312"
bigclassid=safe(request.QueryString("bigclassid"))
If bigclassid<>"" Then
Set Re=New RegExp
Re.IgnoreCase=true
Re.Global=false
Re.Pattern = "^[0-9]{1,3}$"
If Not Re.Test(bigclassid) Then
Response.Write "非法参数"
Response.End
End If%>
<!--#include file="iconn.asp"-->
<%On error Resume Next
set p = conn.execute("select * from smallclass where bigclassid="&bigclassid&"")
If Err Then
Err.Clear
Response.Write "查询出错"
Response.End
End If
If Not p.Eof Then
html = "<select name='smallclassid'>"&vbnewline
Do While Not p.Eof
html = html&"<option value='"&p("smallclassid")&"'>"&p("smallclassname")&"</option>"&vbnewline
p.Movenext
Loop
html = html&"</select>"
Else
html = "<select name='smallclassid'><option value='0' selected>暂无小类</option></select>"
End If
p.Close
Set p = Nothing
Conn.Close
Set Conn = Nothing
Response.write html
html = ""
End If
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询