asp+ajax和数据库驱动的二级联动菜单

<%@language="vbscript" codepage="936"%>
<!--#include file="conn.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%>

<%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='select2'>"&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
%>
// JavaScript Document
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.onreadystatechange=handle;
xmlhttpobj.open('get',"getsubcategory.asp?bigclassid="+bigclassid+"&number="+Math.random(),true);//get方法 加个随机数。

xmlhttpobj.send(null);
}
}

function handle(){//客户端监控函数
//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=xmlhttpobj.readystate;//服务器处理中
//}
//}

}

<!--#include file="conn.asp" -->
<%
set cmd = conn.execute("select bigclassid,bigclassname from bigclass")
tempid=cmd("bigclassid")
%>
<select name="menu" onChange="getsubcategory(this.value);">

<%
if not cmd.eof then
do while not cmd.eof
bigclassid= cmd("bigclassid")
bigclassname = cmd("bigclassname")
%>
<option value="<%=bigclassid%>"><%=bigclassname%></option>
<%
cmd.movenext
loop
end if
cmd.close
set cmd = nothing
%>
</select>
<div id="subclass">
<select name="submenu">

<%
set cxd = conn.execute("select * from smallclass where bigclassid=" & tempid)
if not cxd.eof then
do while not cxd.eof
smallclassid= cxd("smallclassid")
smallclassname = cxd("smallclassname")%>
<option value="<%=smallclassid%>"><%=smallclassname%></option>
<%
cxd.movenext
loop
cxd.close
set cxd = nothing
else
html = "<select name='smallclassid'><option value='0' selected>暂无小类</option></select>"
response.write html
end if
%>
</select>
</div>

时间: 2024-09-19 21:21:13

asp+ajax和数据库驱动的二级联动菜单的相关文章

基于asp+ajax和数据库驱动的二级联动菜单_php技巧

index.asp 页面代码 复制代码 代码如下: <!--#include file="conn.asp" --> <% set cmd = conn.execute("select bigclassid,bigclassname from bigclass") tempid=cmd("bigclassid") %> <select name="menu" onChange="gets

ajax读取数据库内容实现二级联动下拉选择菜单示例

本文为大家介绍下使用ajax技术读取数据库内容并生成二级联动下拉选择菜单,具体实现如下,感兴趣的朋友可以参考下,希望对大家有所帮助   复制代码 代码如下: <PRE class=javascript name="code"></PRE><PRE class=javascript name="code">---------------------这是ajax(javascript)代码 ----------------------

ajax读取数据库内容实现二级联动下拉选择菜单示例_AJAX相关

复制代码 代码如下: <PRE class=javascript name="code"></PRE><PRE class=javascript name="code">---------------------这是ajax(javascript)代码---------------------------</PRE><PRE class=javascript name="code">&l

一个强健 实用的asp+ajax二级联动菜单(有演示和附源程序打包下载)_应用技巧

一个强健 实用的ajax二级联动菜单(有演示和附源程序打包下载) 前些天在搞后台的时候要用到二级联动的菜单,到网上去找了半天也没找到满意的,不是这错就是那错,在选择的时候有时候不能返回.真是郁闷.     后来就看到有人用ajax写了无限级分类(牛,呵呵,本人看不懂.).就想到我那个后台不也可以用ajax试试,虽然比用javascript的慢点,但我这个实用.强健..不会出错,也不会选择某个大类后再返回无选择状态小类为空的状态.呵呵.文件目录:如图 主要代码如下:index.asp 复制代码 代

我的ASP之旅—二级联动菜单制作

菜单|联动菜单|菜单|联动菜单  这个问题其实已经蛮老了,不过作为刚学ASP3个月的我来说,还是有必要写下来强化自己的基础知识.         就拿最常用的"省市下拉列表联动"作为例子吧!         在我们制作网站会员注册信息时,一般会涉及到填写自己所在省/市,如果用input或textarea做成填写形式不太理想.所以大部分网站都会选择联动下来列表形式,做起来也不算很复杂,同时看上去也很轻松.         具体做法如下:         1.设计数据库         我

我的ASP之旅:二级联动菜单制作

菜单|联动菜单     这个问题其实已经蛮老了,不过作为刚学ASP3个月的我来说,还是有必要写下来强化自己的基础知识.     就拿最常用的"省市下拉列表联动"作为例子吧!     在我们制作网站会员注册信息时,一般会涉及到填写自己所在省/市,如果用input或textarea做成填写形式不太理想.所以大部分网站都会选择联动下来列表形式,做起来也不算很复杂,同时看上去也很轻松.         具体做法如下:         1.设计数据库         我们选用Access数据库.

jsp从数据库获取数据填充下拉框实现二级联动菜单的方法_JSP编程

本文实例讲述了jsp从数据库获取数据填充下拉框实现二级联动菜单的方法.分享给大家供大家参考,具体如下: 项目告一段落,现在将遇到的比较实用的东西记录下来,写了多遍了,谨记于此,以备查看! 1.首先在数据库中获取第一个下拉框的数据: <s:select listKey="tsFrom" id="t_tsfrom" cssClass="required" listValue="tsFrom" cssStyle="w

AJAX教程实例,ASP+AJAX+ACCESS数据库应用教程(附源码)

access|asp+|数据|数据库|ajax教程 AJAX教程实例[阿里西西原创]  其实说起AJAX的初级应用是非常简单的,通俗的说就是客户端(javascript)与服务端(asp或php等)脚本语言的数据交互. 看完本篇ajax实例教程,我相信你也可以轻松做出一个初级的AJAX应用. 你也可以直接访问:http://www.alixixi.com/web/web/ajax/jiaocheng.html预览此篇ajax教程的源码示例. 好,下面我们就始一步步让你了解AJAX+ASP基础应用

一个用数据库的php二级联动

数据|数据库 <?php /*****************************************************功能:php二级联动菜单***********************作者:冲星***********************************Email:njj@nuc.edu.cn************************日期:2004/10/02****************************请转载时保留版权信息*************