简体   繁体   English

表单验证未发生

[英]form validation not happening

The following is my form : 以下是我的表格:

<form name="login" method="post" action="AdminLoginCheck.jsp" onsubmit="return login()">
Enter your ID : <input type="text" name="master_admin_id" id="master_admin_id"><br>
Enter your Password : <input type="password" name="password" id="password"><br>
<input type="submit" value="Login">
</form>

And my javascript code for form validation is as follows : 我的用于表单验证的JavaScript代码如下:

<script>
        function login()
        {
            var master_admin_id = document.login.master_admin_id;                
            var password = document.login.password;
            if(master_admin_id.value == "")
            {
            window.alert("Enter your ID!");
            return false;
            }
            if(password.value == "")
            {
            window.alert("Enter your password!");
            return false;
            }
            return true;
        }            
        </script>

yet even if i press submit without entering the fields..., it is only reloading the page indicating that entered ID and password did not match in the database hence asking to enter again... 即使我按提交而不输入字段...,它也只是重新加载页面,指示输入的ID和密码在数据库中不匹配,因此要求再次输入...

what could be the error? 可能是什么错误?

The problem is that login is already defined. 问题是login已经定义。 It is your form. 这是你的表格。 So when you call return login() it doesn't call your function, but try to return your form. 因此,当您调用return login()它不会调用您的函数,而是尝试返回您的表单。

Just rename the function (or the form) and it will work. 只需重命名该函数(或窗体)即可使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM