日期:2014-05-17  浏览次数:20786 次

如何在提交表单后验证验证码对错?
我用的是Dreamweaver+asp+access做的
如何在提交表单后验证验证码对错?对就提交。错就返回重写。谁给段完整的代码。非常感谢。

我有段验证的代码如下
  <%
  if Session("GetCode")<>Request.Form("verifycode") then 
  response.write " <script> alert( '验证码输入错误 '); </script> "
  response.end
  end if
   
  %>

如果我把这段放进去。结果是人家还没输验证码就说验证码错误。请大神结合这段帮我写全代码。。要求在点提交表单后验证对错。对就提交表单。错误就不提交表单。返回重写。

------解决方案--------------------
这个后台代码会在页面加载前就执行....
你的正确值存在Session中(Session)是服务器对象,不提交怎么验证?
你可以用Ajax单独提交验证码,判断返回结果
也可以全部提交,再验证.
------解决方案--------------------
kong.htm(无内容页面)


yzasp.asp(验证页面)



<% 
if request.querystring="" then 
bb="no"
else

if Session("GetCode")<>Request.Form("verifycode") then 
ss="<font face='宋体' size='2' color=red><b>验证码错误,请重新填写!</b></font>"
bb="no"
else
ss="<img src='../images/ok.gif'>"
bb="ok"
end if 
end if
%>
<script language="JavaScript">parent.yzxs1.innerHTML="<% =ss %>"</Script>
<script language="JavaScript">parent.yzxs2.innerText="<% =bb %>"</Script>


aa.asp(验证码页)
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>

<form method="POST" action="zctj.asp" name="yanzheng">
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="88">
<tr>
<td width="32%" height="88"><input type="text" name="yzm" size="20" onkeyup="VBScript:yzcx()"></td>
<td width="28%" height="88" id="yzxs1"></td>
<td width="40%" height="88" id="yzxs2"></td>
</tr>
<tr style="display:none;">
<td height="9" width="666" valign="middle" align="left" colspan="3" background="../images/contantb_bg3.gif"><font face="隶书" size="3" color="#0000FF">
<iframe src="kong.htm" width="20" height="10" allowtransparency="true" scrolling="no" style="bgcolor='#FFFFEC'" frameborder="0" id="yrnc"></iframe></font></td>
</tr>
</table>
</form>

</body>

</html>
<script Language="VBScript">

sub yzcx()
if yanzheng.yzm.value="" then 
 
else
if len(yanzheng.yzm.value)<4 then  '我用的是4位验证
yzxs2.innerText="no"
else
if len(yanzheng.yzm.value)>4 then
yzxs2.innerText="no"
yzxs1.innerHTML="<font face='宋体' size='2' color=red><b>验证码错误!</b></font>"
else
yzxs1.innerHTML="<font face='宋体' size='2' color=red><b>正在查询,请稍候……