为什么表单没有提交

时间:2014-07-03 07:18:27

标签: javascript php html5

    <html>
    <head><br></head>
    <body>
    <meta charset="UTF-8">

    <script type="text/javascript">
    function validate()
    {

        var pass1=document.form1.pw.value;
        var user=document.form1.name.value;
                if(user.length==0)
                {
                         alert( "Username Should not be blanck");
                         document.form1.name.focus();
                         return false;
                }
            if (pass1.length == 0) 
            {
                alert("You must enter  password");
                document.form1.pw.focus();
                return false;
             }
              if(pass1.length<4)
              {  
                  alert("Password length should not be less than 4 characters");
                   document.form1.pw.focus();
                    return false;    
              } 
               //alert("submit");
           document.form1.submit();
                return true;          
    }
    </script>
      <form action="Authenticate1.php" method="post"  name="form1" id="form1" enctype="multipart/form-data"  ">
    <table width="40%"  border="1"> 
     <tr> 
     <td width="20%"> </td> 
     <td width="40%"> </td>
     <tr> 
    <td><b><h2></h2>Login:</td>
     <tr><td>USER NAME&nbsp&nbsp<input type="text" name="name"></td></tr>
    <tr><td>PASSWORD&nbsp&nbsp<input type="password" name="pw"></td></tr> 
    <tr><td><input type="button" name="submit" value="LOGIN" onclick="return validate()";> </td>
     </tr>  </tr>
    </table> 
    </form> 
    </body> 
    </html> 

请帮帮我  你可以告诉我为什么我的表格没有提交是否有任何错误。请帮我。 我已经使用输入类型的按钮作为提交进行验证然后它工作,但我想通过JS提交它

2 个答案:

答案 0 :(得分:3)

看起来存在歧义问题,因为您已将提交按钮命名为submit

<input type="button" name="submit"
                           ^^^^^^ Here.

当你这样做时:

document.form1.submit();

它正在尝试将submit视为对象,并且您收到错误:

Uncaught TypeError: object is not a function

只需更改按钮的名称即可。

答案 1 :(得分:0)

由于此错误,表单未提交:

enter image description here

仔细检查代码,看起来你的表单html有错字:

<form .... enctype="multipart/form-data"  ">
------------------------------------------^ you have extra double-quote

所以,将这行html更新为:

<form action="Authenticate1.php" method="post"  name="form1" id="form1" enctype="multipart/form-data">

然后将您的提交按钮的名称重命名为submit以外的其他内容:

<input type="button" name="submitBtn" value="LOGIN" onclick="return validate()";>

现在应该可以了。

相关问题