| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1261 人关注过本帖
标题:【求助】为什么表单提交总是不验证~~~
只看楼主 加入收藏
无名小子
Rank: 1
等 级:新手上路
威 望:1
帖 子:30
专家分:0
注 册:2007-8-11
收藏
 问题点数:0 回复次数:9 
【求助】为什么表单提交总是不验证~~~
究竟错在那里啊。。。。先谢谢各位~~


<!-- #include file="database.asp" -->
<style type="text/css">
<!--
.style1 {font-size: xx-large}
-->
</style>
<html><head><title>用户注册</title>
<script language="javascript" src="common/common.js"></script>
</head>
<body>
 
<form name="submit" action="login.asp?addnew=1" method="post" onSubmit="//return check();" target="_blank">
 
<table align="center" width="80%">
 <tr>
   <td width="40%">&nbsp;</td>
   <td width="60%">&nbsp;</td>
 </tr>
 <tr>
   <td height="23">&nbsp;</td>
   <td class="style1"><strong>用户注册</strong></td>
 </tr>
 <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
 </tr>
 <tr><td>
 <div align="right">用户名:</div></td>
            
            <td><input name="u_user" type="text" id="u_user" value=""></td>
    </tr>
          <tr>
            <td><div align="right">密 码:</div></td>
            <td><input name="u_code" type="password" id="u_code" value=""></td>
          </tr>
          <tr>
            <td><div align="right">确认密码:</div></td>
            <td><input name="u_code2" type="password" id="u_code2" value=""></td>
          </tr>
          <tr>
            <td><div align="right">昵称:</div></td>
            <td><input name="u_nick" type="text" id="u_nick" value=""></td>
          </tr>
          <tr>
            <td><div align="right">出生日期:</div></td>
            <td><input name="year" type="text" id="year" value="" size="5">
              
                 
                <select name="month">
                  <%
                  dim month
                  for month=1 to 12
                %>
                  <option value="<%=month%>"><%=month%></option>
                  <%
                    next
                %>
                </select>
              
              <select name="day">
                <%
                  dim day
                  for day=1 to 31
                %>
                <option value="<%=day%>"><%=day%></option>
                <%
                    next
                %>
              </select>
            日 </td>
          </tr>
          <tr>
            <td><div align="right">身份证号码:</div></td>
            <td><input name="u_ID" type="text" id="u_ID" value=""></td>
          </tr>
          <tr>
            <td><div align="right">学历:</div></td>
            <td><select name="degree">
              <option value="-1">请选择...</option>
              <%
                    sql="select * from degree"
                    set rstDegree=opentable(sql,0)
                    while not rstDegree.EOF
                %>
              <option value="<%=rstDegree("id")%>"><%=rstDegree("d_name")%></option>
              <%
                rstDegree.movenext
                Wend
                set rstDegree=nothing
                closedatabase()
                %>
            </select></td>
          </tr>
<tr>
            <td><div align="right">职业:</div></td>
            <td><input name="u_occputation" type="text" id="u_occputation" value=""></td>
    </tr>
          <tr>
            <td><div align="right">Email:</div></td>
            <td><input name="u_email" type="text" id="u_email" value=""></td>
          </tr>
          <tr>
            <td><div align="right">联系电话:</div></td>
            <td><input name="u_phone" type="text" id="u_phone" value=""></td>
          </tr>
          <tr>
            <td><div align="right">手机号码:</div></td>
            <td><input name="u_cellphone" type="text" id="u_cellphone" value=""></td>
          </tr>
          <tr>
            <td><div align="right">联系地址:</div></td>
            <td><input name="u_address" type="text" value=""></td>
          </tr>
          <tr>
            <td><div align="right">个人爱好:</div></td>
            <td><textarea name="u_hobby" rows="5" id="u_hobby"></textarea></td>
          </tr>
<tr>
            <td height="43" colspan="2"><div align="center">
                <input type="submit" name="Submit" value="注册">
                <input type="reset" name="Submit" value="重置">
            </div></td>
</tr></table>
 </form>
            
</body>
<script language="javascript">
function check()
{
    try
    {
        checkID
            (
            document.all.u_code.value,
            document.all.year.value,
            document.all.month.options(document.all.sel_month.selectedIndex).value,
            document.all.day.options(document.all.sel_day.selectedIndex).value,
            );
    }
    catch(e)
    {
        alert(e);
        return false;
    }
    try
    {
        checkdate(document.all.year.value,
        document.all.month.options(document.all.sel_month.selectedIndex).value,
        document.all.day.options(document.all.sel_day.selectedIndex).value)
    }
    catch(e)
    {
        alert("出生日期"+e);
        return false;
    }
    if(document.all.u_user.value=="")
        {
            alert("用户名不能为空");
            return false;
        }
    if(document.all.u_nick.value=="")
        {
            alert("昵称不能为空");
            return false;
        }
    if(document.all.u_code.value!=document.all.u_code2.value   )
        {
            alert("两次输入密码不一致");
            return false;
        }
    if(document.all.u_code.value=="")
        {
            alert("密码不能为空");
            return false;
        }
    else
        {
            if(document.all.u_code.value.length<6)
                alert("密码不能小于6位");
            return false;
        }
    if(document.all.degree.options(document.all.sel_u_degree.selectedIndex).value=="-1")
        {
            alert("请选择学历");
            return false;
        }
    return true;
}

</script>
</html>
搜索更多相关主题的帖子: 表单 验证 用户 注册 
2008-07-09 22:39
无名小子
Rank: 1
等 级:新手上路
威 望:1
帖 子:30
专家分:0
注 册:2007-8-11
收藏
得分:0 
表单信息是正确的,但是在点击提交的时候为什么总是不验证,而直接去注册了呢?
那位高人出来帮我看看。。谢谢啊。。
2008-07-09 22:43
无名小子
Rank: 1
等 级:新手上路
威 望:1
帖 子:30
专家分:0
注 册:2007-8-11
收藏
得分:0 
为什么没人来帮我啊。。。
2008-07-09 23:09
无名小子
Rank: 1
等 级:新手上路
威 望:1
帖 子:30
专家分:0
注 册:2007-8-11
收藏
得分:0 
一下是common.js文件


function checkdata(year,month,day)
{
    year=parseint(year);
    if(isnan(year))throw("输入年份不正确");
    var nowdate=new date()
    var nowyear=nowdate.getfullyear();
    if(year<1900||year>nowyear)
        {
            throw("输入年份不正确");
            }
    month=praseint(month)
    day=praseint(day)
    var datevalue
    try
        {
            datevalue=new date(year,month,day);
            }
    catch(e)
        {
            throw("不正确");
            }
    return datevalue;
}
function checkID(ID,year,month,day)
{
    var len=ID.length
    if(len!=15||len!=18)throw("身份证号码位数不正确");
    if(len==15)
        {
            if(ID.substr(6,2)!=year.substr(2,2)throw("身份证号码不正确");
            if(ID.substr(8,2)!=month)throw("身份证号码不正确");
            if(ID.substr(10,2)!=day)throw("身份证号码不正确");
            }
    else
        {
            if(ID.substr(8,2)!=year.substr(2,2)throw("身份证号码不正确");
            if(ID.substr(10,2)!=month)throw("身份证号码不正确");
            if(ID.substr(12,2)!=day)throw("身份证号码不正确");
            }
    }
}
2008-07-10 00:13
madpbpl
Rank: 4
等 级:贵宾
威 望:11
帖 子:2876
专家分:244
注 册:2007-4-5
收藏
得分:0 
<html>
<head>
<title>用户注册</title>
<style type="text/css">
<!--
.style1 {font-size: xx-large}
-->
</style>
<script language="javascript" src="common/common.js"></script>
<script language="javascript">
function check()
{
    try
    {
       checkID(document.all.year.value,
        document.all.month.options(document.all.sel_month.selectedIndex).value,
        document.all.day.options(document.all.sel_day.selectedIndex).value)
    }
    catch(e)
    {
        alert(e);
        return false;
    }
    try
    {
        checkdate(document.all.year.value,
        document.all.month.options(document.all.sel_month.selectedIndex).value,
        document.all.day.options(document.all.sel_day.selectedIndex).value)
    }
    catch(e)
    {
        alert("出生日期"+e);
        return false;
    }
    if(document.all.u_user.value=="")
        {
            alert("用户名不能为空");
            return false;
        }
    if(document.all.u_nick.value=="")
        {
            alert("昵称不能为空");
            return false;
        }
    if(document.all.u_code.value!=document.all.u_code2.value   )
        {
            alert("两次输入密码不一致");
            return false;
        }
    if(document.all.u_code.value=="")
        {
            alert("密码不能为空");
            return false;
        }
    else
        {
            if(document.all.u_code.value.length<6)
                alert("密码不能小于6位");
            return false;
        }
    if(document.all.degree.options(document.all.sel_u_degree.selectedIndex).value=="-1")
        {
            alert("请选择学历");
            return false;
        }
    return true;
}

</script>
</head>
<body>

<form name="submit" action="?addnew=1" method="post" onSubmit="return check();" target="_blank">

<table align="center" width="80%">
<tr>
   <td width="40%"> </td>
   <td width="60%"> </td>
</tr>
<tr>
   <td height="23"> </td>
   <td class="style1"><strong>用户注册</strong></td>
</tr>
<tr>
   <td> </td>
   <td> </td>
</tr>
<tr><td>
<div align="right">用户名:</div></td>
            
            <td><input name="u_user" type="text" id="u_user" value=""></td>
    </tr>
          <tr>
            <td><div align="right">密 码:</div></td>
            <td><input name="u_code" type="password" id="u_code" value=""></td>
          </tr>
          <tr>
            <td><div align="right">确认密码:</div></td>
            <td><input name="u_code2" type="password" id="u_code2" value=""></td>
          </tr>
          <tr>
            <td><div align="right">昵称:</div></td>
            <td><input name="u_nick" type="text" id="u_nick" value=""></td>
          </tr>
          <tr>
            <td><div align="right">出生日期:</div></td>
            <td><input name="year" type="text" id="year" value="" size="5">
              
                 
                <select name="month">
                  <%
                  dim month
                  for month=1 to 12
                %>
                  <option value="<%=month%>"><%=month%></option>
                  <%
                    next
                %>
                </select>
              
              <select name="day">
                <%
                  dim day
                  for day=1 to 31
                %>
                <option value="<%=day%>"><%=day%></option>
                <%
                    next
                %>
              </select>
            日 </td>
          </tr>
          <tr>
            <td><div align="right">身份证号码:</div></td>
            <td><input name="u_ID" type="text" id="u_ID" value=""></td>
          </tr>
          <tr>
            <td><div align="right">学历:</div></td>
            <td><select name="degree">
              <option value="-1">请选择...</option>
              <%
                    sql="select * from degree"
                    set rstDegree=opentable(sql,0)
                    while not rstDegree.EOF
                %>
              <option value="<%=rstDegree("id")%>"><%/=rstDegree("d_name")%></option>
              <%
                rstDegree.movenext
                Wend
                set rstDegree=nothing
                closedatabase()
                %>
            </select></td>
          </tr>
<tr>
            <td><div align="right">职业:</div></td>
            <td><input name="u_occputation" type="text" id="u_occputation" value=""></td>
    </tr>
          <tr>
            <td><div align="right">Email:</div></td>
            <td><input name="u_email" type="text" id="u_email" value=""></td>
          </tr>
          <tr>
            <td><div align="right">联系电话:</div></td>
            <td><input name="u_phone" type="text" id="u_phone" value=""></td>
          </tr>
          <tr>
            <td><div align="right">手机号码:</div></td>
            <td><input name="u_cellphone" type="text" id="u_cellphone" value=""></td>
          </tr>
          <tr>
            <td><div align="right">联系地址:</div></td>
            <td><input name="u_address" type="text" value=""></td>
          </tr>
          <tr>
            <td><div align="right">个人爱好:</div></td>
            <td><textarea name="u_hobby" rows="5" id="u_hobby"></textarea></td>
          </tr>
<tr>
            <td height="43" colspan="2"><div align="center">
                <input type="submit" name="Submit1" value="注册">
                <input type="reset" name="Submit2" value="重置">
            </div></td>
</tr></table>
</form>
            
</body>

</html>
2008-07-10 02:05
dhdhzzw
Rank: 1
等 级:新手上路
帖 子:949
专家分:0
注 册:2007-8-13
收藏
得分:0 
第一   把fuction 写在提交前面。。。
第二   <form name="submit" action="login.asp?addnew=1" method="post" onSubmit="//return check();" target="_blank">
去掉      //
2008-07-10 09:14
无名小子
Rank: 1
等 级:新手上路
威 望:1
帖 子:30
专家分:0
注 册:2007-8-11
收藏
得分:0 
谢谢楼上2位的帮忙。。但是我按你们说的做了,还是没有解决问题。。那问题还可能出在那呢?
2008-07-10 10:08
无名小子
Rank: 1
等 级:新手上路
威 望:1
帖 子:30
专家分:0
注 册:2007-8-11
收藏
得分:0 
我把5楼的代码直接复制过去居然成HTTP 500错误了。。。我的QQ304386221
能指点下我吗?
2008-07-10 10:11
dhdhzzw
Rank: 1
等 级:新手上路
帖 子:949
专家分:0
注 册:2007-8-13
收藏
得分:0 
把这一段没用的去掉1!!!
  try
    {
        checkID
            (
            document.all.u_code.value,
            document.all.year.value,
            document.all.month.options(document.all.sel_month.selectedIndex).value,
            document.all.day.options(document.all.sel_day.selectedIndex).value,
            );
    }
    catch(e)
    {
        alert(e);
        return false;
    }
    try
    {
        checkdate(document.all.year.value,
        document.all.month.options(document.all.sel_month.selectedIndex).value,
        document.all.day.options(document.all.sel_day.selectedIndex).value)
    }
    catch(e)
    {
        alert("出生日期"+e);
        return false;
    }
==============================================

把语句改为
<script language="javascript">
function check()
{
  
    if(document.all.u_user.value=="")
        {
            alert("用户名不能为空");
            return false;
        }
    if(document.all.u_nick.value=="")
        {
            alert("昵称不能为空");
            return false;
        }
    if(document.all.u_code.value!=document.all.u_code2.value   )
        {
            alert("两次输入密码不一致");
            return false;
        }
    if(document.all.u_code.value=="")
        {
            alert("密码不能为空");
            return false;
        }
   
            if(document.all.u_code.value.length<6)
               { alert("密码不能小于6位");
            return false;
        }

  // else
   //{ return true;}
}
2008-07-11 11:57
无名小子
Rank: 1
等 级:新手上路
威 望:1
帖 子:30
专家分:0
注 册:2007-8-11
收藏
得分:0 
谢谢楼上的大侠。。。非常感激。。。这个问题困惑了我好久,能问下,为什么TRY语句错了吗?
2008-07-11 22:35
快速回复:【求助】为什么表单提交总是不验证~~~
数据加载中...
 
   



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

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