[英]My javascript validation is displaying error
我正在尝试使用php中的javascript验证电子邮件和密码。 但它显示给我错误:-
{"error": "Shell form does not validate{'html_initial_name': u'initial-js_lib', 'form': <mooshell.forms.ShellForm object at 0xa50990c>, 'html_name': 'js_lib', 'label': u'Js lib', 'field': <django.forms.models.ModelChoiceField object at 0xa69d64c>, 'help_text': '', 'name': 'js_lib'}"}
我的PHP代码是
<form id="formLogin" name="formLogin" method="post" action=" " onsubmit="return validateForm()/">
<div class="divLogin">
<table>
<tr>
<td> Enter your Email: </td>
<td> <input type="text" name="txtEmail" required="required" autocomplete="off" /> </td>
</tr>
<tr>
<td> Enter your Password: </td>
<td> <input type="password" name="pwd" minlength="6" required="required" autocomplete="off" /> </td>
</tr>
</table>
</div>
<div>
<input type="submit" class="btnLogin" value="Go" style="display:inline-block; margin-left:350px; font-weight:bold; font-size:12px;" />
</div>
</form>
我的JS代码是
function validateForm(){
var checkemail=document.forms["formLogin"]["txtEmail"].value;
var atpos=checkemail.indexOf("@");
var dotpos=checkemail.lastIndexOf(".");
var checkpwd=document.forms["formLogin"]["pwd"].value;
if (checkemail==null){
document.getElementById("checkemail").innerHTML = "Please Enter Email Address";
return false;
}
if (checkpwd==null)
{
document.getElementById("checkpwd").innerHTML = "Please Enter Password";
return false;
}
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=checkemail.length)
{
alert("Not a valid e-mail address");
return false;
}
if (checkpwd==null || checkpwd=="")
{
alert("Password must be filled out");
return false;
}
}
在表单标签中,在onsubmit函数调用之后,您还有一个额外的“ /”
替换下面的行
<form id="formLogin" name="formLogin" method="post" action=" " onsubmit="return validateForm()/">
与
<form id="formLogin" name="formLogin" method="post" action=" " onsubmit="return validateForm()">
html5“必需”的验证程序将首先响应另一件事,然后将调用validateForm函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.