hi,
这是我从网页中提取出来的关于验证码的部分,现在的情况是,如果验证码为空,会弹出对话框提示"输入验证码";如果验证码输入错误,整个网页会刷新,之前输入的用户信息会丢失,不得不重新输入.
如何才能在验证码输入错误之后也只跳出提示"错误,请重新输入",而不刷新整个网页呢?
谢谢大家!<script type="text/javascript">
function ltrim(stringToTrim) {
return stringToTrim.replace(/^\s+/,"");
}
function validateForm()
{
var okSoFar=true
with (document.practitioner_profile)
{
if (firstname.value=="" && okSoFar)
{
okSoFar=false
alert("Please enter your first name.")
firstname.focus()
}
if (lastname.value=="" && okSoFar)
{
okSoFar=false
alert("Please enter your last name.")
lastname.focus()
}
//省略若干...

if (verify_code.value=="" && okSoFar)
{
okSoFar=false
alert("Please enter your security code.")
verify_code.focus()
}
if (okSoFar==true)  submit();
}
}

 <div class="practsubmit">
       <div class="signupform"><h4>* Security Code:</h4> <p>Please type in what you see in the box below and press submit. Characters are case-sensitive.</p></div>
       <div class="signupform"><img id="captcha" src="index.php?option=com_egbcaptcha&amp;width=150&amp;height=50&amp;characters=5" /><br /><input id="verify_code" name="verify_code" type="text" /></div>
   <input type="button" class="button" value="Send" name="B1" ONCLICK="javascript:validateForm()">&nbsp;<input type="reset" class="button" value="Clear" name="clear">
</div>
   

解决方案 »

  1.   

    验证码一般都是通过服务端验证吧。你这里只判断了验证码是否为空。没判断是否正确,用ajax判断
      

  2.   


    那请问如何用ajax判断呢?在下新手...有没有例子参考之类的?
    谢谢!
      

  3.   

    http://w3school.com.cn/ajax/index.aspPS:你还要在index.php里面写php代码前台后台对应起来才行的。
      

  4.   

    你去谷歌查一下ajax例子看下就明白了
      

  5.   

    ajax 解决不刷新,这是通过js当然判断不刷新页面。
     你请求服务器判断是否正确 就需要刷新,通过ajax就可以不刷新判断是否正确了。