ajax+asp批量数据验证

cxp19871102 2010-12-02 02:03:38
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><!-- #include file="../Ajax_register/conn.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>禁用物质检测系统</title>
<style type="text/css">
<!--
body {
background-image: url(../image/exptextb.jpg);
}
.STYLE7 {
font-size: 24px;
color: #FF0000;
font-weight: bold;
}
.STYLE8 {color: #FF0000}
.STYLE10 {color: #FF0000; font-size: 14px; }
.STYLE11 {
color: #000000;
font-weight: bold;
}
-->
</style>
<script type="text/javascript">
function SelectSubmit(){
document.all.registerForm.submit();
return true;
}
function submit1(){
if(document.all.bgbh.value.length==0)
alert("请输入报告编号!");
return false
}

</script>
</head>
<script type="text/javascript" src="../html/function.js"></script>
<body>
<form action="insert_liaohao.asp" method="post" name="form1" id="form1" onsubmit="this.action=this.action+document.form1.liaohao1.value">
<div align="center"><span class="STYLE7">报告编号对应新增物料料号</span> </div>
<table width="1165" height="314" align="center">
<tr>
<td height="23"><div align="left"><a href="../index.asp"> 返回主页</a></div></td>
<td><span class="STYLE11">报告编号:</span></td>
<td colspan="2"><input name="bgbh" type="text" id="bgbh" value="" />
<span class="STYLE8">*</span></td>
<td colspan="4"><strong>MSDS文件位置:</strong>
<input name="msds" type="file" id="msds" /></td>
</tr>
<tr>
<td width="107" height="18">物料料号1:</td>
<td width="176"><input name="liaohao1" type="text" id="liaohao1" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td width="118">物料料号2:</td>
<td width="168"><input name="liaohao2" type="text" id="liaohao2" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td width="106">物料料号3:</td>
<td width="168"><input name="liaohao3" type="text" id="liaohao3" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td width="116">物料料号4:</td>
<td><input name="liaohao4" type="text" id="liaohao4" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
</tr>
<tr>
<td height="18">物料料号5:</td>
<td><input name="liaohao5" type="text" id="liaohao5" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号6:</td>
<td><input name="liaohao6" type="text" id="liaohao6" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号7:</td>
<td><input name="liaohao7" type="text" id="liaohao7" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号8:</td>
<td><input name="liaohao8" type="text" id="liaohao8" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
</tr>
<tr>
<td height="22">物料料号9:</td>
<td><input name="liaohao9" type="text" id="liaohao9" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号10:</td>
<td><input name="liaohao10" type="text" id="liaohao10" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号11:</td>
<td><input name="liaohao11" type="text" id="liaohao11" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号12:</td>
<td><input name="liaohao12" type="text" id="liaohao12" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
</tr>
<tr>
<td height="18">物料料号13:</td>
<td><input name="liaohao13" type="text" id="liaohao13" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号14:</td>
<td><input name="liaohao14" type="text" id="liaohao14" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号15:</td>
<td><input name="liaohao15" type="text" id="liaohao15" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号16:</td>
<td><input name="liaohao16" type="text" id="liaohao16" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
</tr>
<tr>
<td height="18">物料料号17:</td>
<td><input name="liaohao17" type="text" id="liaohao17" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号18:</td>
<td><input name="liaohao18" type="text" id="liaohao18" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号19:</td>
<td><input name="liaohao19" type="text" id="liaohao19" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
<td>物料料号20:</td>
<td><input name="liaohao20" type="text" id="liaohao20" onblur="CheckUserName(this.value)"/><div align="left" id="CheckUserName" class="alert"></div></td>
</tr>
<%
end if %>
<tr>
<td colspan="8"><div align="center">
<input type="submit" name="Submit1" value="保 存" onclick="return submit1()"/>
<input type="reset" name="Submit" value="重 置" />
</div></td>
</tr>
<tr>
<td colspan="8"><span class="STYLE10">备注:带*号必须输入</span></td>
</tr>
</table>
</form>
</body>
</html>
以上是要实现批量数据验证的页面,有20个Textbox,现在已通过一个用ajax+asp的验证数据是否和数据库中的记录重复,现在想验证20个textbox的写法不会,请指教。
<!-- #include file="conn.asp" -->
<%
Response.Charset="gb2312"
if Request.ServerVariables("Request_method") <> "POST" then Response.End
if request("liaohao1")<>"" then
'response.Write request("liaohao1")&"<br>"
UserName=Trim(Request.QueryString("liaohao1"))
if not Conn.Execute("Select id From liaohao where liaohao1='"&UserName&"'" ).eof Then
Response.write("<img onload='nosubmit()' src='/jiny/Ajax_register/images/check_error.gif' align=absmiddle /> "&UserName&"料号已存在,请重新输入!")
else
Response.write("<img src='/jiny/Ajax_register/images/check_right.gif' />")
end if

end if
conn.close
set conn=nothing
%>
这个是check.asp 实现验证的功能页面

function Ajax_GetXMLHttpRequest() {
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
}
function Ajax_CallBack(FormName,ID,URL){
var x = Ajax_GetXMLHttpRequest();
var ID = document.getElementById(ID);
x.open("POST",URL);
x.setRequestHeader("REFERER", location.href);
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
x.onreadystatechange = function(){if(x.readyState == 4 && x.status == 200 && ID){ID.innerHTML=x.responseText;}}
var encodedData=""
if (document.forms.length > 0 && FormName) {
var form = document.forms[FormName];
for (var i = 0; i < form.length; ++i) {
var element = form.elements[i];
if (element.name) {
var elementValue = null;
if (element.nodeName == "INPUT") {
var inputType = element.getAttribute("TYPE").toUpperCase();
if (inputType == "TEXT" || inputType == "PASSWORD" || inputType == "HIDDEN") {
elementValue = escape(element.value);
} else if (inputType == "CHECKBOX" || inputType == "RADIO") {
if (element.checked) {
elementValue = escape(element.value);
}
}
} else if (element.nodeName == "SELECT" || element.nodeName == "TEXTAREA") {
elementValue = escape(element.value);
}
if (elementValue) {
if(encodedData==""){
encodedData = element.name + "=" + encodeURIComponent(elementValue);
}
else{
encodedData += "&" + element.name + "=" + encodeURIComponent(elementValue);
}
}
}
}

}
x.send(encodedData);
}
//Ajax End




function ShowCheckResult(ObjectID, Message, ImageName) {
obj = document.getElementById(ObjectID);
obj.style.display = '';
obj.innerHTML = '<img src="/jiny/Ajax_register/images/check_'+ImageName+'.gif" align="absmiddle" /> ' + Message;
}

function CheckUserName(UserName) {

Ajax_CallBack(false,"CheckUserName","check1.asp?liaohao1=" + escape(UserName));

}
这个是function.js 是实现ajax功能的js.
...全文
154 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenzhenNBA 2010-12-03
  • 打赏
  • 举报
回复
漏了一点,修改见红色,不知你的表结构是怎么样的?如果有需要看看兰色部分这里是否用变动。。。

xName=Conn.Execute("Select id From liaohao where liaohao1='" & UserName & "'")(0)


shenzhenNBA 2010-12-02
  • 打赏
  • 举报
回复


SERVER端:

<!-- #include file="conn.asp" -->
<%
response.CacheControl="no-cache"
response.AddHeader "progma","no-cache"
response.Expires=-1

Response.Charset="gb2312"
UserName=Trim(Request.QueryString("tempBH"))
if UserName<>"" then
dim reStr,xName
reStr=""
xName=Conn.Execute("Select id From liaohao where liaohao1='" & UserName & "'")
if xName="" Then
reStr="no_exist"
else
reStr="exist"
end if
end if
conn.close
set conn=nothing

response.Write reStr
%>
shenzhenNBA 2010-12-02
  • 打赏
  • 举报
回复
LZ写得很乱,SERVER,CLIENT都修改一些,试看....

CLIENT 端:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
response.CacheControl="no-cache"
response.AddHeader "progma","no-cache"
response.Expires=-1
%>
<!--#include file="../Ajax_register/conn.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> 禁用物质检测系统</title>
<style type="text/css">
<!--
body {
background-image: url(../image/exptextb.jpg);
}
.STYLE7 {
font-size: 24px;
color: #FF0000;
font-weight: bold;
}
.STYLE8 {color: #FF0000}
.STYLE10 {color: #FF0000; font-size: 14px; }
.STYLE11 {
color: #000000;
font-weight: bold;
}
-->
</style>
<script type="text/javascript" language="javascript">
function $(id){
return "string" == typeof(id) ? document.getElementById(id) : id ;
}

//---------------------------------------------------------------------

function createXMLHttp(){
var objXMLHttp;
if (window.XMLHttpRequest){
objXMLHttp = new XMLHttpRequest();
if (objXMLHttp.overrideMimeType){
objXMLHttp.overrideMimeType("text/xml");
}
}else if(!objXMLHttp && window.ActiveXObject){
var activexName = ["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
for (var i = 0; i < activexName.length; i++) {
try{
objXMLHttp = new ActiveXObject(activexName[i]);
}catch(e){
continue;
}
if(objXMLHttp) break;
}
}
if(objXMLHttp){
return objXMLHttp;
}else{
alert("Can not create XMLHttpRequest object, maybe update your browser to new version.\n\nXMLHttpRequest对象创建失败! 请升级你的浏览器");
return;
}
}

//------------------------------------------------------------------------------------

function CheckUserName(inputObjID,outputObjID){
var xmlhttp=null;
var refBH=$(inputObjID).value;
if(refBH=="") return;
var goURL="check1.asp?tempBH="+refBH;
if(!xmlhttp) xmlhttp=createXMLHttp();
xmlhttp.open("GET",goURL,true);
xmlhttp.onreadystatechange=function(){callBackFun(xmlhttp,inputObjID,outputObjID);};
xmlhttp.send(null);

}


//------------------------------------------------------------------------------------

function callBackFun(XMLHttp,inputObjID,outputObjID){
var xmlhttp=XMLHttp;
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var r=xmlhttp.responseText; //return value: exist = have exist the BianHao, no_exist = no exist the BianHao
r=r.toLowerCase();
$(outputObjID).style.fontSize="12px";
$(outputObjID).style.fontFamily="arial";
if(r=="exist"){
$(inputObjID).style.border="2px solid red";
$(outputObjID).innerHTML="这个编号已经存在";
}else{
$(inputObjID).style.border="1px solid #333333";
$(outputObjID).innerHTML="这个编号不存在,可以使用";
}
}
}
}

function resetBox(inputObjID,outputObjID){
$(inputObjID).border="1px solid #333333";
if($(outputObjID).innerHTML!="")
$(outputObjID).innerHTML="";
}

//------------------------------------------------------------------------------------

function SelectSubmit(){
document.all.registerForm.submit();
return true;
}

function submit1(){
if(document.all.bgbh.value.length==0)
alert("请输入报告编号!");
return false;
}

</script>
</head>
<script type="text/javascript" src="../html/function.js"></script>
<body>
<form action="insert_liaohao.asp" method="post" name="form1" id="form1" onsubmit="this.action=this.action+document.form1.liaohao1.value">
<div align="center"><span class="STYLE7">报告编号对应新增物料料号</span> </div>
<table width="1165" height="314" align="center">
<tr>
<td height="23"><div align="left"><a href="../index.asp"> 返回主页</a></div></td>
<td><span class="STYLE11">报告编号:</span></td>
<td colspan="2"><input name="bgbh" type="text" id="bgbh" value="" />
<span class="STYLE8">*</span></td>
<td colspan="4"><strong>MSDS文件位置:</strong>
<input name="msds" type="file" id="msds" /></td>
</tr>
<tr>
<td width="107" height="18">物料料号1:</td>
<td width="176"><input name="liaohao1" type="text" id="liaohao1" onclick="resetBox('liaohao1','CheckUserName1');" onblur="CheckUserName('liaohao1','CheckUserName1')"/><div align="left" id="CheckUserName1" class="alert"></div></td>
<td width="118">物料料号2:</td>
<td width="168"><input name="liaohao2" type="text" id="liaohao2" onclick="resetBox('liaohao2','CheckUserName2');" onblur="CheckUserName('liaohao2','CheckUserName2')"/><div align="left" id="CheckUserName2" class="alert"></div></td>
<td width="106">物料料号3:</td>
<td width="168"><input name="liaohao3" type="text" id="liaohao3" onclick="resetBox('liaohao3','CheckUserName3');" onblur="CheckUserName('liaohao3','CheckUserName3')"/><div align="left" id="CheckUserName3" class="alert"></div></td>
<td width="116">物料料号4:</td>
<td><input name="liaohao4" type="text" id="liaohao4" onclick="resetBox('liaohao4','CheckUserName4);" onblur="CheckUserName('liaohao4','CheckUserName4')"/><div align="left" id="CheckUserName4" class="alert"></div></td>
</tr>
<tr>
<td height="18">物料料号5:</td>
<td><input name="liaohao5" type="text" id="liaohao5" onclick="resetBox('liaohao5','CheckUserName5');" onblur="CheckUserName('liaohao5','CheckUserName5')"/><div align="left" id="CheckUserName5" class="alert"></div></td>
<td>物料料号6:</td>
<td><input name="liaohao6" type="text" id="liaohao6" onclick="resetBox('liaohao6','CheckUserName6');" onblur="CheckUserName('liaohao6','CheckUserName6')"/><div align="left" id="CheckUserName6" class="alert"></div></td>
<td>物料料号7:</td>
<td><input name="liaohao7" type="text" id="liaohao7" onclick="resetBox('liaohao7','CheckUserName7');" onblur="CheckUserName('liaohao7','CheckUserName7')"/><div align="left" id="CheckUserName7" class="alert"></div></td>
<td>物料料号8:</td>
<td><input name="liaohao8" type="text" id="liaohao8" onclick="resetBox('liaohao8','CheckUserName8');" onblur="CheckUserName('liaohao8','CheckUserName8')"/><div align="left" id="CheckUserName8" class="alert"></div></td>
</tr>
<tr>
<td height="22">物料料号9:</td>
<td><input name="liaohao9" type="text" id="liaohao9" onclick="resetBox('liaohao9','CheckUserName9');" onblur="CheckUserName('liaohao9','CheckUserName9')"/><div align="left" id="CheckUserName9" class="alert"></div></td>
<td>物料料号10:</td>
<td><input name="liaohao10" type="text" id="liaohao10" onclick="resetBox('liaohao10','CheckUserName10');" onblur="CheckUserName('liaohao10','CheckUserName10')"/><div align="left" id="CheckUserName10" class="alert"></div></td>
<td>物料料号11:</td>
<td><input name="liaohao11" type="text" id="liaohao11" onclick="resetBox('liaohao11','CheckUserName11');" onblur="CheckUserName('liaohao11','CheckUserName11')"/><div align="left" id="CheckUserName11" class="alert"></div></td>
<td>物料料号12:</td>
<td><input name="liaohao12" type="text" id="liaohao12" onclick="resetBox('liaohao12','CheckUserName12');" onblur="CheckUserName('liaohao12','CheckUserName12')"/><div align="left" id="CheckUserName12" class="alert"></div></td>
</tr>
<tr>
<td height="18">物料料号13:</td>
<td><input name="liaohao13" type="text" id="liaohao13" onclick="resetBox('liaohao13','CheckUserName13');" onblur="CheckUserName('liaohao13','CheckUserName13')"/><div align="left" id="CheckUserName13" class="alert"></div></td>
<td>物料料号14:</td>
<td><input name="liaohao14" type="text" id="liaohao14" onclick="resetBox('liaohao14','CheckUserName14');" onblur="CheckUserName('liaohao14','CheckUserName14')"/><div align="left" id="CheckUserName14" class="alert"></div></td>
<td>物料料号15:</td>
<td><input name="liaohao15" type="text" id="liaohao15" onclick="resetBox('liaohao15','CheckUserName15);" onblur="CheckUserName('liaohao15','CheckUserName15')"/><div align="left" id="CheckUserName15" class="alert"></div></td>
<td>物料料号16:</td>
<td><input name="liaohao16" type="text" id="liaohao16" onclick="resetBox('liaohao16','CheckUserName16');" onblur="CheckUserName('liaohao16','CheckUserName16')"/><div align="left" id="CheckUserName16" class="alert"></div></td>
</tr>
<tr>
<td height="18">物料料号17:</td>
<td><input name="liaohao17" type="text" id="liaohao17" onclick="resetBox('liaohao17','CheckUserName17');" onblur="CheckUserName('liaohao17','CheckUserName17')"/><div align="left" id="CheckUserName17" class="alert"></div></td>
<td>物料料号18:</td>
<td><input name="liaohao18" type="text" id="liaohao18" onclick="resetBox('liaohao18','CheckUserName18');" onblur="CheckUserName('liaohao18','CheckUserName18')"/><div align="left" id="CheckUserName18" class="alert"></div></td>
<td>物料料号19:</td>
<td><input name="liaohao19" type="text" id="liaohao19" onclick="resetBox('liaohao19','CheckUserName19');" onblur="CheckUserName('liaohao19','CheckUserName19')"/><div align="left" id="CheckUserName19" class="alert"></div></td>
<td>物料料号20:</td>
<td><input name="liaohao20" type="text" id="liaohao20" onclick="resetBox('liaohao20','CheckUserName20');" onblur="CheckUserName('liaohao20','CheckUserName20')"/><div align="left" id="CheckUserName20" class="alert"></div></td>
</tr>
<%
'end if '//what ?! comment it for now
%>
<tr>
<td colspan="8"><div align="center">
<input type="submit" name="Submit1" value="保 存" onclick="return submit1()"/>
<input type="reset" name="Submit" value="重 置" />
</div></td>
</tr>
<tr>
<td colspan="8"><span class="STYLE10">备注:带*号必须输入</span></td>
</tr>
</table>
</form>
</body>
</html>

cxp19871102 2010-12-02
  • 打赏
  • 举报
回复
这个主要是想用ajax验证页面上20个textbox,实现输入一个验证一个,只要不为空就验证,看是否和数据库里面的记录重复。如果重复就提示‘XXX料号已存在,请重新输入’,不重复就提示正确,这个问题已经困扰我一上午时间,在线等待,很着急!!

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧