婪的拼音怎么写:高分求 联动菜单!~ (asp + Javascript)

来源:百度文库 编辑:高校问答 时间:2024/04/25 13:17:30
联动菜单:(选择一个时显示相应的拦目)
要求:
1、是用 asp + Javascript 编写的;
2、菜单的各个可选项目是从数据库中读取;
3、提交表单时有相应的值(即option 中value的值是来自数据库);
5、要求代码完全,最好是提供下载地址。

感激不尽!~
我不希望看到转载别人的文章,希望看到自己原创的,或者经过修改别人后的代码,如果自己都没有搞懂就来回答!~ 那就免了,最好是自己做过的人回答!~ 如果自己做过的人回答,哪怕就是提供一点思想,我都很感激!~楼下的注意,我要从数据库中读取!~

http://www.treye.com/caidan.rar

ASP + XML + JavaScript 实现动态无限级联动菜单
--------------------------------------------------------------------------------
(日期:2005年10月9日 作者:gaoshou 人气:3 查看:[大字体 中字体 小字体]) 结合ASP来完成对数据库值的读取,然后写入XML文件,再用JavaScript读出来并且控制它的联动。
这儿的关键是把数据库内的N层数据类读出来:
我的数据库表结构是这样的:
'tbl_Class
列名 数据类型 长度 说明
ClassID int 4 类ID
ModuleID int 4 模块ID
GroupID int 2 标识一个组
ClassName nvarchar 50 类别名称
ParentID int 2 连接到组(0表示是父类)

'##################我的ASP代码如下####################
'我把连接数据库的代码忽略。

'函数名字:OpenXml(FileName)
'入口参数: filename 需要连接或打开的xml文件名
'返回值 :XmlDoc就是一个成功装载XML文档的对象了。
' 有错误则打印错误信息strError
'------------------------------------------------

function OpenXml(filename)
dim strSourceFile ,XmlDoc,strError
strSourceFile = filename
Set XmlDoc = Server.CreateObject("Microsoft.XMLDOM") '创建XMLDOM实例
XmlDoc.async = false
XmlDoc.load(strSourceFile)
OpenXml=XmlDoc.parseerror.errorcode
if XmlDoc.parseerror.errorcode<>0 then
strError="<h2>error"&XmlDoc.parseerror.errorcode&"</h2>"
strError=strError&XmlDoc.parseerror.reason&"<br>"
strError=strError&XmlDoc.parseerror.url&"<br>"
strError=strError&XmlDoc.parseerror.line&"<br>"
strError=strError&XmlDoc.parseerror.filepos&"<br>"
strError=strError&XmlDoc.parseerror.srcText&"<br>"
response.write strError '输出错误
else
set OpenXml=XmlDoc '返回实例
end if
end function

'------------------------------------------------
'函数名字:CloseXml()
'参数: XmlDoc XML组件实例
'------------------------------------------------
function CloseXml(XmlDoc)
if IsObject(XmlDoc) then
set XmlDoc=nothing
end if
end function

'------------------------------------------------
'函数名字:SelectXmlNode
'参数:XmlDoc XML组件实例
' e 元素的名字
'返回元素实例
'------------------------------------------------
function SelectXmlNode(XmlDoc,e)
dim n

set n=XmlDoc.selectSingleNode("//" & e )
set selectXmlNode= n

end function

Dim n,np,MaxGroup,root,xmlDoc,nt,filename,s,ss,TorF
filename=server.mappath("demo.xml")
set xmlDoc=openXML(filename)'打开XML
RemoveAllNodes xmlDoc,"Root"'把Root和它下面的子项清除,这样可以多次方便读写
set root= xmlDoc.createElement("Root")
xmlDoc.appendChild root'创建一个顶层元素
sql="select Max(GroupID) from tbl_Class " '读出最大的层次
set rs=cn.execute(sql)
if isnull(rs(0)) then MaxGroup=0 else MaxGroup=rs(0) '如果为null 表示没有数据
s="":ss=""
set nt=xmldoc.createElement("item")
nt.setAttribute "text", "请选择"
root.appendChild nt '创建一个元素
for i=1 to MaxGroup '开始循环
sql="select * from tbl_Class where GroupID=" & i '由底层向顶层读取
set rs=cn.execute(sql)
TorF=False '为了每一个层上都创建一个“请选择”的空取。
do while rs.eof =false '开始读取下层的数据
Set n = xmlDoc.createElement("item" & rs("ClassID")) '创建一个命名为item + ID号的标记元素
n.setAttribute "text",rs("ClassName")'把它的属性“text”设置为数据库表内的

ClassName
n.setAttribute "value",rs("ClassID")'把它的属性“value”设置为数据库表内的

ClassID
if rs("ParentID")>0 then '是有上层数据的
set np=selectXmlNode(xmlDoc,"item" & rs("ParentID")) '把它的上层数据元素先读出保存在np
if TorF=false then '如果TorF为False值时
set nt=xmldoc.createElement("item") '创建一个元素保存在nt
nt.setAttribute "text", "请选择"'把它的text属性设置为“请选择”
np.appendChild nt 'np把它加为子元素
end if
TorF=true '设置true
np.appendChild n 'np 把n加为子元素
else
root.appendChild n '如果是第一层数据就把它加入为root下的一个子元素
end if
rs.movenext '下一条指针
loop

ss=ss & "<SELECT id=Select" & i & " width=1 ></SELECT></span>" '每有一层就创建一个

<select>
s=s & ",'Select" & i & "'" '把每个<select>的id 保存在变量s,它的格式为:id1,id2,id3,id4

next
xmlDoc.save filename '正式保存Xml文件
CloseXml xmlDoc '关闭Xml文件

response.write ss '直接把<select>输出到文档
s=mid(s,2)

//在HTM文件内调用xmlselect.js
<SCRIPT language=JavaScript src="xmlselect.js"></SCRIPT>
<SCRIPT language=JavaScript>
<!--//** power by fason
function init() {
var Sel = [<%=s%>];
attachSelect("demo.xml", Sel,["论坛导航"]);
};//-->
</SCRIPT>
init();

//#########我把它的JS代码贴出来,作者叫:蒲佛信,http://fason.nease.net/samples/xmlselect/这儿有示例和代码。

//-----------------------------xmlselect.js文件开始-------------------------------

//-----------------------------------------------------/
// NichName :fason
// Autho :Forbes Pu(蒲佛信)
// Email :fason_pfx@hotmail.com
// HomePage :http://fason.nease.net
// Blog :http://blog.mvpcn.net/fason/
// http://blog.csdn.net/fason/
//
// function :attachSelect(sXMLSrc, aSel[, sStore])
// param1 :sXMLSrc(URL of XML data source)
// param2 :aSel(array of SELECT controls's ID)
// param3 :array of default value when display
//-----------------------------------------------------/

function attachSelect(sXMLSrc, aSel, sStore) {
var oXML = CreateXmlDocument();
var oDocument = null;
var store = sStore ? sStore : [];
var Sel = new Array();

for (var i=0; i<aSel.length; i++)
Sel[i] = document.getElementById(aSel[i]);

if (!oXML){ throw new Error('Not support!\nplease install a XML parser');return; }
oXML.onreadystatechange = function () {
if (oXML.readyState == 4) {
attachXML();
}
};
oXML.load(sXMLSrc);

function CreateXmlDocument() {
if (document.implementation && document.implementation.createDocument) {
var doc = document.implementation.createDocument("", "", null);
if (doc.readyState == null) {
doc.readyState = 1;
doc.addEventListener("load", function () {
doc.readyState = 4;
if (typeof doc.onreadystatechange == "function")
doc.onreadystatechange();
}, false);
}
return doc;
}
else if (window.ActiveXObject) {
var prefix = ["MSXML3","MSXML2","MSXML","Microsoft"];
for (var i=0;i<prefix.length;i++) {
try {
var doc = new ActiveXObject(prefix[i] +

".DomDocument");
doc.setProperty("SelectionLanguage","XPath");
return doc;
} catch (e) {}
}
}
return null;
};

function attachXML() {
oDocument = oXML.documentElement;
if (!oDocument) { throw new Error('No XML data!'); return; }
for (var i=0;i<aSel.length-1;i++){
addEvent(Sel[i], "onchange", function(x) {
return function () { doChange(x); }
}(i+1));
}
doChange(0);
};

function selectXMLNode(x) {
var sPath = "/*";
var oDoc = oDocument;
for (var i=0;i<x;i++)
sPath += "/*[" + (Sel[i].selectedIndex+1) + "]";
if (typeof(oDoc.selectSingleNode)!='undefined') return

oDoc.selectSingleNode(sPath);
else {
var doc=oDoc.nodeType==9?oDoc:oDoc.ownerDocument;
var res = doc.createNSResolver(oDoc.nodeType==9?

oDoc.documentElement:oDoc);
return doc.evaluate(sPath,oDoc, res, 9, null).singleNodeValue;
}
};

function addEvent(el, sHandler, fnc) {
if (el.attachEvent) {
el.attachEvent(sHandler, fnc);
} else if (el.addEventListener) {
el.addEventListener(sHandler.replace(/on/i, ''), fnc, false);
} else {
el[sHandler] = fnc;
}
};

function doChange(n) {
var el = selectXMLNode(n);
var nodes = el ? el.childNodes :[];
var s = Sel[n];
var f = 0;
if (nodes.length>0) {
with (s){
length = 0;
for (var i = 0,j = 0;i<nodes.length;i++) {
if (nodes[i].nodeType!=1)continue;
var t = nodes[i].getAttribute("text");
var v = nodes[i].getAttribute("value") ? nodes

[i].getAttribute("value") : t;
if (v == store[n]) f = j;
options[j++] = new Option(t, v);
}
options[f].selected = true;
}
if (++n<Sel.length) doChange(n);
} else {
for (var i=n; i<Sel.length; i++) {
with (Sel[i]) {
length = 0;
options[0] = new Option('--');
options[0].selected = true;
}
}
}
};
};

//-----------------------------xmlselect.js文件结束-------------------------------

由于Xml的操作简便直接,使用起来得心应手。

三级联动,用asp控制输出js,一次过调出所有项目数据,参考代码
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="inc/conn.asp"-->
<!-- #include file="inc/checklogin.asp"-->
<!--#include file="inc/md5.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>manageproductitem</title>
<link href="inc/style.css" rel="stylesheet" type="text/css">
<script language="javascript">
function check()
{
if( window.myform.ChannelId1.value==""){alert("please select big class");return false}
if( window.myform.ChannelId2.value==""){alert("please select small class");return false}
if( window.myform.ChannelId3.value==""){alert("please select product");return false}
quan=window.myform.num.value;
if( window.myform.ino.value==""){alert("please input Item No.");return false}
if( window.myform.itemname.value==""){alert("please input item name");return false}
if( window.myform.num.value==""){alert("please input num");return false}
for (nIndex=0; nIndex<quan.length; nIndex++)
{
cCheck = quan.charAt(nIndex);
if (!IsDigit(cCheck))
{
alert("num must be a number");
return false;
}
}
}
function IsDigit(cCheck)
{
return (('0'<=cCheck) && (cCheck<='9'));
}

var g_selProvince;
var g_selCity;
var g_selCounty;
//一级目录
var Provinces=new Array();
<%
set rs1=server.CreateObject("adodb.recordset")
rs1.open "select * from bigclass",conn,3,3
i=0
do while not rs1.eof
%>
Provinces[<%=i%>]=new Array("<%=rs1("bigclassid")%>","<%=trim(rs1("bigclassname"))%>");
<%rs1.movenext
i=i+1
loop%>

//Array("与下级索引","显示的值")

//二级目录
var Citys=new Array();
<%
set rs2=server.CreateObject("adodb.recordset")
rs2.open "select * from smallclass",conn,3,3
i=0
do while not rs2.eof
%>
Citys[<%=i%>]=new Array("<%=rs2("bigclassid")%>","<%=rs2("smallclassid")%>","<%=trim(rs2("smallclassname"))%>");

<%rs2.movenext
i=i+1
loop%>

//Array("本级索引","与下级索引","显示的值")

//三级目录
var Countys=new Array();
<%
set rs3=server.CreateObject("adodb.recordset")
rs3.open "select * from product",conn,3,3
i=0
do while not rs3.eof
%>
Countys[<%=i%>]=new Array("<%=rs3("smallclassid")%>","<%=rs3("productid")%>","<%=trim(rs3("productname"))%>"),

<%rs3.movenext
i=i+1
loop%>

//Array("本级索引","与下级索引","显示的值")

function FillProvinces(selProvince)
{
selProvince.options[0]=new Option("select bigclass","");
for(i=0;i<Provinces.length;i++)
{
selProvince.options[i+1]=new Option(Provinces[i][1],Provinces[i][0]);
selProvince.options[0].selected=true;
}
selProvince.length=i+1;
}
function FillCitys(selCity,ProvinceCode)
{
selCity.options[0]=new Option("select small class","");
count=1;
for(i=0;i<Citys.length;i++)
{
if(Citys[i][0].toString()==ProvinceCode)
{
selCity.options[count]=new Option(Citys[i][2],Citys[i][1]);
selCity.options[0].selected = true;
count=count+1;
}
}
selCity.length=count;
}
function FillCountys(selCounty,CityCode)
{
selCounty.options[0]=new Option("select product","");
count=1;
for(i=0;i<Countys.length;i++)
{
if(Countys[i][0]==CityCode)
{
selCounty.options[count]=new Option(Countys[i][2],Countys[i][1]);
selCounty.options[0].selected = true;
count=count+1;
}
}
selCounty.length=count;
}
function City_onchange()
{
FillCountys(g_selCounty,g_selCity.value);
}
function Province_onchange()
{
FillCitys(g_selCity,g_selProvince.value);
City_onchange();
}
function InitCitySelect(selProvince,selCity,selCounty)
{
g_selProvince=selProvince;
g_selCity=selCity;
g_selCounty=selCounty;
selProvince.onchange=Province_onchange;
selCity.onchange=City_onchange;
FillProvinces(selProvince);
Province_onchange();
}

</script>
</head>

<body><br>

<table width="80%" border="0" align="center" cellpadding="3" cellspacing="0">
<FORM name=myform action="manageproductitem.asp?action=add" method="post" onSubmit="return check()">
<tr>
<td align="right">product:</td>
<td><SELECT id=ChannelId1 name=ChannelId1></SELECT>
<SELECT id=ChannelId2 name=ChannelId2></SELECT>
<SELECT id=ChannelId3 name=ChannelId3></SELECT>
<SCRIPT language=javascript>
InitCitySelect(document.myform.ChannelId1,document.myform.ChannelId2,document.myform.ChannelId3);
</SCRIPT></td>
</tr>
<tr>
<td align="right">item:</td>
<td><input name="itemname" type="text" id="itemname"></td>
</tr>
<tr>
<td align="right">No.:</td>
<td><input name="ino" type="text" id="ino"></td>
</tr>
<tr>
<td align="right">nums:</td>
<td><input name="num" type="text" id="num" size="4"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="submit"></td>
</tr>
</FORM>
</table>

<br>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
<tr>
<td>product item </td>
<td>No.</td>
<td>product</td>
<td>small class name</td>
<td>big classname</td>
<td>num</td>
<td>edit</td>
</tr>
<% dim rs,sql
i=0
page=request("page")
if page<1 then page=1
page=int(page)
sql="select item.*,product.*,smallclass.*,bigclass.* from item,product,smallclass,bigclass where item.productid=product.productid and item.smallclassid=smallclass.smallclassid and item.bigclassid=bigclass.bigclassid order by item.itemid desc"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,3,3
pagesize=10
if rs.eof then
response.Write("no recoord")
else
rs.pagesize=pagesize
rs.absolutepage=page
do while not rs.eof and i<pagesize
%>
<form name="editpro" action="manageproductitem.asp?action=edit&id=<%=rs("itemid")%>" method="post">
<tr>
<td><input name="itemname2" type="text" id="itemname2" value="<%=trim(rs("itemname"))%>" size="16"></td>
<td><input name="ino2" type="text" id="ino2" value="<%=trim(rs("ino"))%>" size="12"></td>
<td><%=rs("productname")%></td>
<td><%=rs("smallclassname")%></td>
<td><%=rs("bigclassname")%></td>
<td><input name="num2" type="text" id="num2" value="<%=trim(rs("num"))%>" size="10"></td>
<td><input type="button" value="del" onClick="location.href='manageproductitem.asp?action=del&id=<%=rs("itemid")%>'"> <input type="submit" value="edit"></td>
</tr></form>
<%
rs.movenext
i=i+1
loop
end if%>
</table>
<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="right"><a href="manageproductitem.asp?page=<%=page-1%>">Proview</a> <a href="manageproductitem.asp?page=<%=page+1%>">Next</a></td>
</tr>
</table>

</body>
</html>
<%
if request("action")="add" then
set rs4=server.CreateObject("adodb.recordset")
rs4.open "select * from item where bigclassid="&cint(trim(request("ChannelId1")))&" and smallclassid="&cint(trim(request("ChannelId2")))&" and productid="&cint(trim(request("ChannelId3")))&"",conn,3,3
do while not rs4.eof
if trim(rs4("itemname"))=trim(request("itemname")) then
response.Write("<script>alert('the user name was exist');location.href='manageproductitem.asp'</script>")
fla=1
end if
rs4.movenext
loop

if fla<>1 then
rs4.addnew
rs4("itemname")=trim(request("itemname"))
rs4("bigclassid")=cint(trim(request("ChannelId1")))
rs4("smallclassid")=cint(trim(request("ChannelId2")))
rs4("productid")=cint(trim(request("ChannelId3")))
rs4("ino")=trim(request("ino"))
rs4("num")=cint(trim(request("num")))
rs4.update
response.Redirect("manageproductitem.asp")
end if
rs4.close
set rs4=nothing

end if

if request("action")="del" then
set rs5=server.CreateObject("adodb.recordset")
rs5.open "delete from item where itemid="&cint(trim(request("id")))&"",conn,3,3
response.Redirect("manageproductitem.asp")
end if
if request("action")="edit" then
set rs6=server.CreateObject("adodb.recordset")
rs6.open "select * from item where itemid="&cint(trim(request("id")))&"",conn,3,3
rs6("itemname")=trim(request("itemname2"))
rs6("num")=cint(trim(request("num2")))
rs6("ino")=trim(request("ino2"))
rs6.update
response.Redirect("manageproductitem.asp")
end if
%>

通过中转页面回传参数可做无限级联动,缺点是项目多时需多次跳转页面,执行速度较慢

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="inc/conn.asp"-->
<!-- #include file="inc/checklogin.asp"-->
<!--#include file="inc/md5.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>edit manage</title>
<link href="inc/style.css" rel="stylesheet" type="text/css">
<script src="inc/setDate.js"></script>
<script language="javascript">
function check()
{
if( window.myform.Customername.value==""){alert("please input Customername");return false}
if( window.myform.Address.value==""){alert("please input Address");return false}
if( window.myform.Tel.value==""){alert("please input Tel");return false}
if( window.myform.Purchasedate.value==""){alert("please input Purchasedate");return false}
if( window.myform.Purchaseloaction.value==""){alert("please input Purchaseloaction");return false}
if( window.myform.invoiceno.value==""){alert("please input invoiceno");return false}
if( window.myform.bigclass.value==""){alert("please input bigclass");return false}
if( window.myform.smallclass.value==""){alert("please input smallclass");return false}
if( window.myform.product.value==""){alert("please input product");return false}
if( window.myform.item.value==""){alert("please input item");return false}
if( window.myform.num.value==""){alert("please input num");return false}
quan=window.myform.num.value;
for (nIndex=0; nIndex<quan.length; nIndex++)
{
cCheck = quan.charAt(nIndex);
if (!IsDigit(cCheck))
{
alert("num must be a number");
return false;
}
}

if( window.myform.Solution.value==""){alert("please input Solution");return false}
if( window.myform.shipdate.value==""){alert("please input shipdate");return false}
}

function IsDigit(cCheck)
{
return (('0'<=cCheck) && (cCheck<='9'));
}

function selectitem()
{ document.all.myform.action="selectitem.asp";
document.all.myform.submit();

}

function submitt()
{ document.all.myform.action="addcustomer.asp?action=add";
document.all.myform.submit();
}

</script>
</head>
<% set ds=server.CreateObject("adodb.recordset")
ds.open "select * from customer",conn,3,3
if ds.eof then
tempno=0
else
do while not ds.eof
tempno=ds("customer")
ds.movenext
loop
end if
tempno=tempno+1
if len(tempno)<5 then
i=5-len(tempno)
for j=1 to i
tempno="0"&cstr(tempno)
next
end if
ds.close
%>
<body>
<p> </p>
<table width="80%" border="0" cellspacing="1" cellpadding="3" align="center" class="table">
<form name="myform" action="" method="post" onSubmit="return check()">
<tr>
<td width="29%" align="right">Date:</td><td width="71%"><input type="text" name="date" value="<%=formatdatetime(now(),2)%>"></td>
</tr>

<tr>
<td align="right">Customer NO.: </td>
<td><input type="text" name="customerno" value="<%=tempno%>"></td>
</tr>
<tr>
<td align="right">Customer name: </td>
<td><input name="Customername" type="text" id="Customername" value="<%=request("Customername")%>"></td>
</tr>
<tr>
<td align="right">Address:</td>
<td><input name="Address" type="text" id="Address" value="<%=request("Address")%>"></td>
</tr>
<tr>
<td align="right">Tel:</td>
<td><input name="Tel" type="text" id="Tel" value="<%=request("Tel")%>"></td>
</tr>
<tr>
<td align="right">Purchase date: </td>
<td><input name="Purchasedate" type="text" id="Purchasedate" onfocus=setday(this) value="<%=request("Purchasedate")%>"></td>
</tr>
<tr>
<td align="right">Purchase loaction: </td>
<td><input name="Purchaseloaction" type="text" id="Purchaseloaction" value="<%=request("Purchaseloaction")%>"></td>
</tr>
<tr>
<td align="right">invoice no:</td>
<td><input name="invoiceno" type="text" id="invoiceno" value="<%=request("invoiceno")%>"></td>
</tr>
<tr>
<td align="right">Purchase Product item: </td>
<td><select name="bigclass" onChange="selectitem()">
<option value="">select big class</option>
<% set rs1=server.CreateObject("adodb.recordset")
rs1.open "select * from bigclass",conn,3,3
do while not rs1.eof
%>
<option value="<%=rs1("bigclassid")%>" <%if request("bigclass")<>"" then if cint(trim(rs1("bigclassid")))=cint(trim(request("bigclass"))) then response.Write("selected") end if end if%>><%=rs1("bigclassname")%></option>
<% rs1.movenext
loop%>
</select>
<select name="smallclass" onChange="selectitem()">
<option value="">select small class</option>
<% if request("bigclass")<>"" then
set rs2=server.CreateObject("adodb.recordset")
rs2.open "select * from smallclass where bigclassid="&cint(trim(request("bigclass")))&"",conn,3,3
do while not rs2.eof%>
<option value="<%=rs2("smallclassid")%>" <%if request("smallclass")<>"" then if cint(trim(rs2("smallclassid")))=cint(trim(request("smallclass"))) then response.Write("selected") end if end if%>><%=rs2("smallclassname")%></option>
<% rs2.movenext
loop
end if
%>
</select>

<select name="product" onChange="selectitem()">
<option value="">select product</option>
<%
if request("smallclass")<>"" then
set rs3=server.CreateObject("adodb.recordset")
rs3.open "select * from product where smallclassid="&cint(trim(request("smallclass")))&"",conn,3,3
do while not rs3.eof
%>
<option value="<%=rs3("productid")%>" <%if request("product")<>"" then if cint(trim(rs3("productid")))=cint(trim(request("product"))) then response.Write("selected") end if end if%>><%=rs3("productname")%></option>
<%rs3.movenext
loop
end if%>
</select>

<select name="item" onChange="selectitem()">
<option value="">select item</option>
<%
if request("product")<>"" then
set rs4=server.CreateObject("adodb.recordset")
rs4.open "select * from item where productid="&cint(trim(request("product")))&"",conn,3,3
do while not rs4.eof
%>
<option value="<%=rs4("itemid")%>"
<%if request("item")<>"" then
if cint(trim(rs4("itemid")))=cint(trim(request("item"))) then
itemn=trim(rs4("itemname"))
response.Write("selected")
end if
end if%>><%=rs4("ino")%></option>
<%rs4.movenext
loop
end if%>
</select> <% if request("item")<>"" then response.Write(itemn) end if%> </td>
</tr>
<tr>
<td align="right">replace number:</td>
<td><input name="num" type="text" id="num" value="<%=request("num")%>"></td>
</tr>
<tr>
<td align="right">Defective Reson: </td>
<td><select name="reason" onChange="selectitem()">
<option value="">select reason</option>
<% if request("product")<>"" then
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from product where productid="&cint(trim(request("product")))&"",conn,3,3
reason=rs("reason")
if reason<>"" then
k=cint(ubound(Split(reason,",")))
dsql="select * from reason where reasonid="&cint(split(reason)(0))
for i=1 to k
dsql=dsql&" or reasonid="&cint(split(reason)(i))
next

set ds=server.CreateObject("adodb.recordset")
ds.open dsql,conn,3,3
do while not ds.eof
%>
<option value="<%=ds("reasonid")%>" <%if request("reason")<>"" then if cint(trim(ds("reasonid")))=cint(trim(request("reason"))) then response.Write("selected") end if end if%>><%=ds("reason")%></option>
<%ds.movenext
loop
end if
end if%>
</select> </td>
</tr>
<tr>
<td align="right">Solution:</td>
<td><select name="Solution">
<option>select Solution</option>
<%
if request("reason")<> "" then
dim rs5,sql5
sql5="select * from Solution"
set rs5=server.CreateObject("adodb.recordset")
rs5.open sql5,conn,3,3
do while not rs5.eof%>
<option value="<%=rs5("Solutionid")%>" <% if rs5("reasonid")=cint(trim(request("reason"))) then response.Write("selected") end if%>><%=trim(rs5("Solution"))%></option>
<% rs5.movenext
loop
end if
%>
</select> <% if request("item")<>"" then %><input type="button" value="check store" onClick="window.open('checkstore.asp?item=<%=request("item")%>','','width=400,height=200')"><% end if%></td>
</tr>
<tr>
<td align="right">Next Shipping Date: </td>
<td><input name="shipdate" type="text" id="shipdate" onfocus=setday(this) value="<%=request("shipdate")%>"></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="button" value="submit" onClick="submitt()"></td>
</tr>
</form>
<% if request("product")<>"" then%>
<tr><td colspan="2" align="center">
<%set pic=server.CreateObject("adodb.recordset")
pic.open "select * from product where productid="&cint(trim(request("product")))&"",conn,3,3%>
<a href="<%=trim(pic("picurl"))%>" target="_blank"><img src="<%=trim(pic("picurl"))%>" border="0" width="200"></a>
</td></tr>
<% end if%>
</table>

</body>
</html>
<% if request("action")="add" then

if numb<0 then
response.Write("<script>alert('no enough store');selectitem();</script>")
else
set itemn=server.CreateObject("adodb.recordset")
set itemn=nothing
set rs6=server.CreateObject("adodb.recordset")
rs6.open "select * from customer",conn,3,3
rs6.addnew
rs6("customerno")=trim(request("customerno"))
rs6("customername")=trim(request("Customername"))
rs6("address")=trim(request("Address"))
rs6("tel")=trim(request("tel"))
rs6("ndate")=trim(request("date"))
rs6("purchasedate")=trim(request("Purchasedate"))
rs6("purchaseloaction")=trim(request("Purchaseloaction"))
rs6("invoiceno")=trim(request("invoiceno"))
rs6("productid")=trim(request("product"))
rs6("itemid")=trim(request("item"))
rs6("cnum")=cint(trim(request("num")))
rs6("reasonid")=trim(request("reason"))
rs6("solutionid")=trim(request("Solution"))
rs6("shipdate")=trim(request("shipdate"))
rs6("issend")=0
rs6.update
rs6.close
set rs6=nothing
response.Write("<script>alert('succeed');location.href='addcustomer.asp';</script>")
end if
end if
%>
中转页面 selectitem.asp
<%
Customername=request("Customername")
Address=request("Address")
Tel=request("Tel")
Purchasedate=request("Purchasedate")
Purchaseloaction=request("Purchaseloaction")
shipdate=request("shipdate")
invoiceno=request("invoiceno")
bigclass=request("bigclass")
smallclass=request("smallclass")
product=request("product")
item=request("item")
reason=request("reason")
num=request("num")
response.Redirect("addcustomer.asp?Customername="&Customername&"&bigclass="&bigclass&"&smallclass="&smallclass&"&product="&product&"&item="&item&"&Address="&Address&"&Tel="&Tel&"&Purchasedate="&Purchasedate&"&Purchaseloaction="&Purchaseloaction&"&invoiceno="&invoiceno&"&shipdate="&shipdate&"&reason="&reason&"&num="&num&"")
%>

最好是用ajax,无页面刷新,不过俺没试过