| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1626 人关注过本帖
标题:表单return checkForm();提交不检查就提交了
只看楼主 加入收藏
fjhtf
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-29
结帖率:46.67%
收藏
已结贴  问题点数:0 回复次数:8 
表单return checkForm();提交不检查就提交了
<form name="reg" method="post" onSubmit="return checkForm1();" action="yp.asp?action=add">  

为什么表单提交的时候不检查文本框的内容呢。只能检测到名字是否为空其他的都检查不出来就成功提交到数据库了。

<SCRIPT language=JavaScript>

function checkForm()


{
  
  if (document.reg.name.value.length ==""){
        alert ("提示:\n\n请输入您的真实姓名!");
        document.reg.name.focus();
        return false;
    }
 if (document.reg.name.value.length < 2 || document.reg.name.value.length > 8){
        alert ("提示:\n\n姓名必须在2-8字之间!");
        document.reg.name.focus();
        return false;
    }
  

 if (document.reg.h_province.value=='请选择')
  {
                alert ("提示:\n\n请选择您目前所在地!")
                document.reg.x_city.focus();
        return false;
  }

      
      
   if (document.reg.Mobile.value=='')
   {
    alert ("提示:\n\n请输入您的手机号码!")
     document.reg.Mobile.focus();
          return false;
   }

   
  return true;
}

</SCRIPT>
搜索更多相关主题的帖子: 检查 language function 真实姓名 return 
2011-09-23 10:07
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:0 
onSubmit="return checkForm1();" 这里是checkForm1 而函数是checkForm()


[ 本帖最后由 dzt0001 于 2011-9-23 11:00 编辑 ]

----我怎能在别人的苦难面前转过脸去----
2011-09-23 10:58
fjhtf
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-29
收藏
得分:0 
回复 楼主 fjhtf
return checkForm()是刚发表的时候写错了。这个一般是哪里出问题不能检查呢。名字文本框的值可以检查,后面的都不行,只要姓名文本框值满足就提交了

if (document.reg.name.value.length ==""){
        alert ("提示:\n\n请输入您的真实姓名!");
        document.reg.name.focus();
        return false;
    }
if (document.reg.name.value.length < 2 || document.reg.name.value.length > 8){
        alert ("提示:\n\n姓名必须在2-8字之间!");
        document.reg.name.focus();
        return false;
    }

宏星电脑医生http://www.
全国淘宝充值旗舰店http://czpt8./
2011-09-23 11:09
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:0 
把表单的HTML代码一起发上来,我来试试

----我怎能在别人的苦难面前转过脸去----
2011-09-23 11:24
fjhtf
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-29
收藏
得分:0 





function checkForm()


{
  
  if (document.reg0.name.value ==""){
        alert ("提示:\n\n请输入您的真实姓名!");
        document.reg0.name.focus();
        return false;
    }
 if (document.reg0.name.value.length < 2 || document.reg0.name.value.length > 8){
        alert ("提示:\n\n姓名必须在2-8字之间!");
        document.reg0.name.focus();
        return false;
    }
  


 if (document.reg0.h_province.value=="请选择")
  {
                alert ("提示:\n\n请选择您目前所在地!")
                document.reg0.h_province.focus();
        return false;
  }

  if (document.reg0.h_city.value0=="城市")
  {
                alert ("提示:\n\n请选择您的户口所在地!")
                document.reg0.h_city.focus();
        return false;
  }

 if (document.reg0.x_province.value=="请选择")
  {
                alert ("提示:\n\n请选择您目前所在地!")
                document.reg0.x_city.focus();
        return false;
  }

  if (document.reg0.x_city.value=="城市")
  {
                alert ("提示:\n\n请选择您的户口所在地!")
                document.reg0.h_city.focus();
        return false;
  }
//if (document.reg0.Stature.value.length ==''){
//        alert ("提示:\n\n请输入您的身高,只能为2-3位数字,如:170!");
//        document.reg0.Stature.focus();
//        return false;
//    }
 
  
 

//  if (document.reg0.Phone.value=='')
//  {
//              alert ("提示:\n\n请输入您的联系电话!")
//              document.reg0.Phone.focus();
//        return false;
//  }

  
  if (document.reg0.Email.value=="")
  {
               alert ("提示:\n\n请输入您的E-mail地址!")
               document.reg0.Email.focus();
           return false;
  }
  if(document.reg0.Email.value.length!=0)
     {
       if (document.reg0.Email.value.charAt(0)=="." ||        
            document.reg0.Email.value.charAt(0)=="@"||      
            document.reg0.Email.value.indexOf('@', 0) == -1 ||
            document.reg0.Email.value.indexOf('.', 0) == -1 ||
            document.reg0.Email.value.lastIndexOf("@")==document.reg0.Email.value.length-1 ||
            document.reg0.Email.value.lastIndexOf(".")==document.reg0.Email.value.length-1)
        {
         alert("提示:\n\nEmail地址格式不正确!");
         document.reg0.Email.focus();
         return false;
         }
      }
    else
     {
      alert("提示:\n\nEmail不能为空!");
      document.reg0.Email.focus();
      return false;
      }
      
      
   if (document.reg0.Mobile.value=="")
   {
    alert ("提示:\n\n请输入您的手机号码!")
     document.reg0.Mobile.focus();
          return false;
   }

   
 if (document.reg0.jieshao.value=='')
  {
    alert ("提示:\n\n请输入您的自我介绍!!")
    document.reg0.jieshao.focus();
      return false;
  }
  if (document.reg0.jieshao.value.length<1)
  {
    window.alert ("提示:\n\n请认真填写您的自我评价(1-500汉字之间)")
    document.reg0.jieshao.focus();
      return false;
  }
   
  if (document.reg0.jieshao.value.length>500)
  {
    window.alert ("提示:\n\n请认真填写您的自我评价(1-500汉字之间)")
     document.reg0.jieshao.focus();
      return false;
  }

 if (document.reg0.Experience.value=='')
  {
    window.alert ("提示:\n\n请输入您的技能专长(工作经历)!!")
     document.reg0.Experience.focus();
      return false;
  }

  if (document.reg0.Experience.value.length<1)
  {
   alert ("提示:\n\n请认真填写您的技能专长(1-500汉字之间)")
     document.reg0.Experience.focus();
      return false;
  }
   
  if (document.reg0.Experience.value.length>500)
  {
    alert ("提示:\n\n请认真填写您的技能专长(1-500汉字之间)")
     document.reg0.Experience.focus();
      return false;
  }
      
 
if (document.reg0.Edulevel.value=='')
  {
    window.alert ("提示:\n\n请填写您的教育背景!")
     document.reg0.Edulevel.focus();
      return false;
  }  

  return true;
}




宏星电脑医生http://www.
全国淘宝充值旗舰店http://czpt8./
2011-09-23 11:52
fjhtf
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-29
收藏
得分:0 
<!--#include file="inc/const.asp" -->
<%Quarters=trim(request.QueryString("Quarters"))
bigclass=trim(request.QueryString("bigclass"))
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="<%=webMeta%>" />
<meta name="description" content="<%=webDesc%>" />
<title><%=webTitle%></title>
<link rel="stylesheet" type="text/css" href="css/css.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/js.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        var navLi = $("#nav ul li a");
        navLi.eq(10).css("color","red");
    });
</script>



</head>

<body>
<!--#include file="js/city.js"-->
<script type="text/javascript" language="JavaScript1.2" src="js/ypadd.js"></script>
<!--#include file="top.asp"-->

<%
function ChangeChr(str)
   ChangeChr=replace(replace(replace(replace(str,"<","&lt;"),">","&gt;"),chr(13),"<br>")," ","&nbsp;")
end function
%>
                  
  <%   
dim action,Quarters
Quarters=trim(request.QueryString("Quarters"))
action=trim(request.QueryString("action"))  
if action="add" then
   Quarters=trim(request.Form("Quarters"))   
   Uname=trim(request.Form("Name"))
   Sex=trim(request.Form("Sex"))
 
   birthday=trim(request.Form("birthday"))
   birthmonth=trim(request.Form("birthmonth"))
   set rs=server.createobject("adodb.recordset")
       sql="select * from HrDemandAccept"
       rs.open sql,conn,1,3
       rs.addnew
       rs("Quarters")=Quarters
       rs("name")=Uname     
       rs("Sex")=Sex     
 
       rs("Adddate")=date()
       rs.update
       rs.close
       set rs=nothing
response.write"<SCRIPT language=JavaScript>alert('友情提示:\n\n提交成功!');"
response.write "window.document.location.href='jo.asp';"&Chr(13)
response.write "</script>" & Chr(13)
else
%>

 <TABLE width=891 border=1 align="center" cellPadding=0 cellSpacing=0 borderColor="#99CCFF" class=gridpad id=table8 style="BORDER-COLLAPSE: collapse" background="images/bg/line.gif">
     
     <TBODY>

宏星电脑医生http://www.
全国淘宝充值旗舰店http://czpt8./
2011-09-23 11:57
fjhtf
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-29
收藏
得分:0 
   
   <form name="reg0" method="post" onSubmit="return checkForm()" action="yp.asp?action=add">  
        <TR>
            <TD height="25" colSpan=4><B>基本资料:<font color=red><%=bigclass%>  </font></B></TD>
       </TR>
            
              <TR>   
                   <TD align=center width=111> <%Quarters=request("Quarters")%><FONT color=#ff0000>*  </FONT>应聘职位:</TD>
                   <TD width=239><input  name=Quarters  id=jobname   value="<%=Quarters%>"  maxLength=15 readonly></TD>
                   <TD align=center width=97><FONT color=#ff0000>*  </FONT>真实姓名:</TD>
                   <TD width=263><INPUT maxLength=15 name=name> <FONT  color=#ff0000>2-8个汉字</FONT></TD>
       </TR>
                <TR>
                   <TD align=center width=111><FONT color=#ff0000>*  </FONT>性&nbsp;&nbsp;&nbsp; 别:</TD>
                   <TD width=239><select style="WIDTH: 154px; HEIGHT: 20px" name=Sex>
                     <option value=1 selected>男</option>
                     <option  value=0>女</option>
                   </select></TD>
                   <TD align=center width=97><FONT color=#ff0000>* </FONT>民&nbsp;&nbsp;&nbsp; 族:</TD>
                   <TD width=263><INPUT maxLength=10 value=汉族 name=minzu> <FONT color=#ff0000>如:汉族</FONT></TD>
       </TR>
                 <TR>
                   <TD align=center width=111><FONT color=#ff0000>* </FONT>最高学历:</TD>
                   <TD width=239>
                   <SELECT style="WIDTH: 154px; HEIGHT: 23px" name=Studydegree>
                                <OPTION value=0>中专</OPTION>
                                <OPTION value=1>高中</OPTION>
                                <OPTION value=2 selected>大专</OPTION>
                                <OPTION value=3>本科</OPTION>
                                <OPTION value=4>硕士</OPTION>
                                <OPTION value=5>博士</OPTION>
                    </SELECT></TD>
                   <TD align=center width=97><FONT color=#ff0000>*  </FONT>婚姻状况:</TD>
                   <TD width=263>
                   <SELECT style="WIDTH: 154px; HEIGHT: 18px" size=1  name=Marry>
                                <OPTION value=0 selected>保密</OPTION>
                                <OPTION value=1>未婚</OPTION>
                                <OPTION value=2>已婚</OPTION>
                              
                 </SELECT> </TD>
                 </TR>
                 <TR>
                    <TD align=center width=111><FONT color=#ff0000>* </FONT>现所在地:</TD>
                    <TD width=239>
    <select id="x_province" name="x_province" onChange = "getCity(this.options[this.selectedIndex].value)" style="WIDTH: 101px; HEIGHT: 24px">
        <option value="">请选择</option>
        <option value="北京市">北京市</option>
        <option value="上海市">上海市</option>
        <option value="天津市">天津市</option>
        <option value="重庆市">重庆市</option>
        <option value="河北省">河北省</option>
        <option value="山西省">山西省</option>
        <option value="内蒙古">内蒙古</option>
        <option value="辽宁省">辽宁省</option>
        <option value="吉林省">吉林省</option>
        <option value="黑龙江">黑龙江</option>
        <option value="江苏省">江苏省</option>
     </select>
    <select id="x_City" name="x_City" style="WIDTH: 101px; HEIGHT: 24px">
        <option>城市</option>
    </select> </TD>
                     <TD align=center width=97>身&nbsp;&nbsp;&nbsp; 高:</TD>
                     <TD width=263><INPUT maxLength=3 size=5  name=Stature> cm&nbsp; <FONT color=#ff0000>必须为整数数字如:170</FONT></TD>
                </TR>
                <TR>
                     <TD align=center width=111><FONT color=#ff0000>*</FONT>户&nbsp;&nbsp;&nbsp; 籍:</TD>
                     <TD width=239>
    <select id="h_Province" name="h_Province" onChange = "getCity1(this.options[this.selectedIndex].value)" style="WIDTH: 101px; HEIGHT: 24px">
        <option value="">请选择</option>
        <option value="北京市">北京市</option>
        <option value="上海市">上海市</option>
        <option value="天津市">天津市</option>
        <option value="重庆市">重庆市</option>
        <option value="河北省">河北省</option>
        <option value="山西省">山西省</option>
        <option value="内蒙古">内蒙古</option>
        <option value="辽宁省">辽宁省</option>
        <option value="吉林省">吉林省</option>
        <option value="黑龙江">黑龙江</option>
        <option value="江苏省">江苏省</option>
        <option value="浙江省">浙江省</option>
        <option value="安徽省">安徽省</option>
    </select>
    <select id="h_City" name="h_City" style="WIDTH: 101px; HEIGHT: 24px">
        <option>城市</option>
    </select> </TD>
                     <TD align=center width=97><FONT color=#ff0000>* </FONT>出生日期:</TD>
                      <TD width=263><FONT size=+0>
                      <select name=birthyear id="birthyear">
                      <%for i=1960 to year(now())%>
                        
                        <option value="<%=i%>"><%=i%></option>
                       <%next%>
                      </select>
                      </FONT> 年 <FONT
                              size=+0>
                      <SELECT name=birthmonth>
                      <%for i=1 to 12%>
                        
                        <option value="<%=i%>"><%=i%></option>
                       <%next%>
                      </SELECT></FONT> 月
                              
                              <FONT  size=+0>
                              <SELECT name=birthday>
                              <%for i=1 to 31%>
                        
                        <option value="<%=i%>"><%=i%></option>
                       <%next%>
                              </SELECT></FONT> 日</TD>
       </TR>
                          <TR>
                            <TD height="25" colSpan=4><B>联系方式:</B></TD>
       </TR>
                         <TR>
                            <TD align=center width=111>联系电话:</TD>
                            <TD colSpan=3><INPUT maxLength=30 size=27  name=Phone> <FONT color=#ff0000>固定电话</FONT></TD>
                        </TR>
                        <TR>
                            <TD align=center width=111><FONT color=#ff0000>*  </FONT>电子邮件:</TD>
                            <TD width=239><input maxlength=50 size=27 name=Email></TD>
                            <TD align=center width=97><FONT color=#ff0000>* </FONT>随身电话: </TD>
                            <TD width=263><INPUT maxLength=15 name=Mobile><FONT color=#ff0000>手机或小灵通</FONT></TD>
                        </TR>
                           <TR>
                            <TD align=center colSpan=4><div align="center">
                                  <input type="submit" name="submit8" value=" 提交 " >
                                  &nbsp;&nbsp;
                                  <input type="reset" name="Submit8" value=" 重置 ">
                                </div></TD>
    </TR></form>
    </TBODY>
</TABLE>

<% end if %>
<!--#include file="bottom.asp"-->
</body>
</html>

宏星电脑医生http://www.
全国淘宝充值旗舰店http://czpt8./
2011-09-23 11:57
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:0 
你给的代码也太多了。


下拉列表框的“请选择”项目的对应Value是""
<option value="">请选择</option>
所以js代码中if (document.reg0.h_province.value=="请选择") 就不对了,应该是if (document.reg0.h_province.value=="")   
所有下拉列表框都油这个问题

代码太多了,不知道还有没有其他问题


----我怎能在别人的苦难面前转过脸去----
2011-09-23 12:43
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
收藏
得分:20 
js代码是严格限制大小写的,你要确认你的表单名称和JS代码大小写一致
2011-09-24 10:11
快速回复:表单return checkForm();提交不检查就提交了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.060196 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved