在用户输入产品编号并回车后,用Javascript脚本修改表单提交地址(如改成goods.asp?cmd=search),并执行表单提交动作。
然后在本页的开头加上:
<%
If Trim(Request("txtProductID")<>"" Then
txtProductID=Trim(Request("txtProductID")
End If
If Trim(Request("cmd"))="search" Then
dim rs,adocon,sqltext,paracode
paracode=document.CutMaterialEditForm.txtProductID.value
sqltext="Select top 1 fldShortName2 From tblItem where fldItemTypeCode='"¶code&"' order by fldShortName2 desc"
set adocon=server.CreateObject("adodb.connection")
adocon.open application("conAims")
set rs=adocon.Execute(sqltext)
If not rs.eof then
txtMaterialName=rs("fldShortName2")
else
txtMaterialName=""
End If
End If
%>
使用后台页面就可以解决.几年前就这么做过,不过对于B/S系统来说,出于性能和资源考滤,并不实用. 拿到现在来说,就是一种ajax技术.
我举个简单例子给你.
我有一个产品表p
CREATE TABLE p (pid INT IDENTITY(1,1),pName VARCHAR(100))
INSERT p (pName)
SELECT 'aba'
UNION ALL SELECT 'bbb'
UNION ALL SELECT 'bbc'
UNION ALL SELECT 'bdd'
此时你表里有4条记录
1 aba
2 bbb
3 bbc
4 bdd
function LetYouSee(obj)
{
if(!isNaN(document.getElementById("pid"+obj).value.trim())) //如果你的编号为字符型,不需要此层检测
{
var v=pid=" + document.getElementById("pid"+obj).value.trim();
var x=new ActiveXObject("Msxml2.DOMDocument");
x.load("http://localhost/test.asp?pid=" + v);
var r=x.selectNodes("//root/product[@pid='" + v + "']");
if(r.length>0)
{
document.getElemetById("pNM"+obj).value=r.item(0).attributes.item(1).value;
}
else
{
alert("没找到记录"); //或者你换成其它人性化一点提示,经如显示个红色的DIV在相应的pNM旁边,提示没有记录.
}
r=null;
x=null;
}
else
{alert("编号格式不对,只能为数字");}
}
test.asp
<%
..
Dim pid:pid=Request("pid")
If pid="" OR Not IsNumeric(pid)
Response.Write("") '//或者这里给出出错提示,并更改上面的JS代码,读取相应的错误提示,下面某些地方错误时也可以这样处理.
Rs.Close
Set Rs=Nothing
Response.End
End If
Set Rs=Conn.Execute("SELECT pName FROM p WHERE pid=" & pid)
If Rs.Eof Then
Response.Write("") '//这里跟上面参数错误时相应也可以改.比如Response.Write(". 上面那句可以将value值改为参数错误
Rs.Close
Set Rs=Nothing
Response.End
End If
Response.Write("")
Rs.CLose
Set Rs=Nothing
%>