提交按钮不会导致验证

时间:2014-10-31 18:13:44

标签: javascript html5 validation form-submit

所以这里的代码虽然有点乱,但我不想错过任何东西



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Login_Default" %>

<!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 id="Head1" runat="server">
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="Facebook for your body!" content=""/>
    <meta name="Dan The Gever" content=""/>
    <link href="../Bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../Bootstrap/css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet"/>
    <link href="../Bootstrap/css/sb-admin-2.css" rel="stylesheet"/>
    <link href="../Bootstrap/font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>

    <script type="text/javascript" src="../Bootstrap/js/jquery-1.11.0.js"></script>
    <script type="text/javascript" src="../Bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../Bootstrap/js/plugins/metisMenu/metisMenu.min.js"></script>
    <script type="text/javascript" src="../Bootstrap/js/plugins/morris/raphael.min.js"></script>
    <script type="text/javascript" src="../Bootstrap/js/plugins/morris/morris.min.js"></script>
    <script type="text/javascript" src="../Bootstrap/js/plugins/morris/morris-data.js"></script>
    <script type="text/javascript" src="../Bootstrap/js/sb-admin-2.js"></script>

    <script type="text/javascript">
       // window.onload = function () {
       //     document.getElementById("passwordReg").onchange = validatePassword;
      //  }
        function validatePassword() {
            var str = document.getElementById("passwordReg").value;
            var re = /^\w+$/;
            if (!re.test(str))
                document.getElementById("passwordReg").setCustomValidity("Password may only contain letters, numbers and underscores!");
            else if (str.length < 8)
                document.getElementById("passwordReg").setCustomValidity("Password must be at least 8 characters long");
            
            
            
        }
        popupVideo = function () {
            var yearRegJS = document.getElementById("yearReg");
            var monthRegJS = document.getElementById("monthReg");
            var dayRegJS = document.getElementById("dayReg");
            dayRegJS.options.length = 0;
            var daysInMonth = DaysInMonth(monthRegJS.value, yearRegJS.value);
            for (var j = 1; j <= daysInMonth; j++) {
                var option = document.createElement("option");
                option.text = j.toString();
                dayRegJS.appendChild(option);
            }
        }
        function DaysInMonth(month, year) {
            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                return 31;
            }
            if (month == 4 || month == 6 || month == 9 || month == 11) {
                return 30;
            }
            if (month == 2) {
                if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                    return 29;
                }
                else {
                    return 28;
                }
            }
            else {
                return -1;
            }
        }
         
    </script>
    <title>Welcome to Bodyspace!</title>
</head>
<body onload="popDate()" >
    <form id="form1" runat="server">
    <div>
    <div class="jumbotron" >
        <h1>Welcome to BodySpace</h1>
       <div class="navbar-collapse collapse">
           <form class="form-signin" role="form">
           <%--<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
           </asp:ScriptManager>--%>
           <table><tr><td>&nbsp; <asp:TextBox type="email" runat="server" name="email" id="email" class="input-block-level" placeholder="Email" required autofocus /></td>
        <td>&nbsp; <input type="password" runat="server" name="pass" id="pass" class="input-block-level" placeholder="Password" required /></td>
            <td>&nbsp; <asp:Button type="submit" runat="server" class="btn btn-success" 
                    text="Sign-In" ID="SignInButton" onclick="SignInButton_Click" /><a class="btn btn-block btn-social btn-facebook"><i class="fa fa-facebook"></i>Sign in with Facebook</a></td>
            </tr></table></form>
        </div>
      </div>
    </div>
    <div>
    <h3>This website and all of it's
    </h3>
        <h3>contents are and will remain free</h3>
    <div class="form-group" >
    <table><tr><td><input runat="server" type="text" name="fNameReg" id="fNameReg" class="form-control" placeholder="First name" required /></td><td><input type="text" runat="server" name="lNameReg" id="lNameReg" class="form-control" placeholder="Last name" required /></td></tr></table>
           <br /><input runat="server" type="text" name="emailReg" id="emailReg" class="form-control" placeholder="Your email adress" required />
           <br /><input runat="server" type="text" name="emailRegCheck" id="emailRegCheck" class="form-control" placeholder="Retype your email adress" required />
           <br /><input runat="server" type="password" name="passwordReg" id="passwordReg" class="form-control" placeholder="Password" required />
         <%--   <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>--%>
           <table>
               <caption>
                   <h4> Birth day</h4> </caption>
                   </tr>
                   <tr>
                       <td>
                           &nbsp;&nbsp;<asp:DropDownList ID="dayReg" runat="server" cssClass="form-control" >
                               <asp:ListItem Selected="True" Value="Invalid">Day</asp:ListItem>
                           </asp:DropDownList>
                       </td>
                       <td>
                           &nbsp;&nbsp;<asp:DropDownList ID="monthReg" runat="server" cssClass="form-control" onchange="popDayReg()" >
                               <asp:ListItem Selected="True" Value="1">1</asp:ListItem>
                               <asp:ListItem Selected="False" Value="2">2</asp:ListItem>
                               <asp:ListItem Selected="False" Value="3">3</asp:ListItem>
                               <asp:ListItem Selected="False" Value="4">4</asp:ListItem>
                               <asp:ListItem Selected="False" Value="5">5</asp:ListItem>
                               <asp:ListItem Selected="False" Value="6">6</asp:ListItem>
                               <asp:ListItem Selected="False" Value="7">7</asp:ListItem>
                               <asp:ListItem Selected="False" Value="8">8</asp:ListItem>
                               <asp:ListItem Selected="False" Value="9">9</asp:ListItem>
                               <asp:ListItem Selected="False" Value="10">10</asp:ListItem>
                               <asp:ListItem Selected="False" Value="11">11</asp:ListItem>
                               <asp:ListItem Selected="False" Value="12">12</asp:ListItem>
                           </asp:DropDownList>
                       </td>
                       <td>
                           &nbsp;&nbsp;<asp:DropDownList ID="yearReg" runat="server" cssClass="form-control"  onchange="popDayReg()">
                               <asp:ListItem Selected="True" Value="Invalid">Year</asp:ListItem>
                           </asp:DropDownList>
                       </td>
                   </tr>
            </table>
          <%-- </ContentTemplate>
         </asp:UpdatePanel>--%>
           <input runat="server" type="radio" name="sexReg" id="maleReg" value="male"/>Male<input type="radio" name="sexReg" id="femaleReg" value="female">Female
           <br />



<asp:Button runat="server" type="submit" class="btn btn-success" text="Register" ID="RegisterButton" onclick="RegisterButton_Click" />






    </div>
    </div>
    </td>
    <td>
    <div><img class="style1" src="../Images/bbingguy.jpg" /></div>
    </td>
    </tr>
    </table>
    </form>
</body>
</html>
&#13;
&#13;
&#13;

编辑:第一个问题解决了,我有一堆无用的表,tr和td声明 但现在问题是 - 注册按钮导致前2个输入的验证是不需要的

如何将验证分成注册并登录?

1 个答案:

答案 0 :(得分:-1)

我解决了这个问题:

  • 清理标签
  • 把注册部分
  • 在runat-server表单中以2种不同的形式登录部分