[英]java script form validation works fine in chrome but not working in firefox?
使用Java脚本进行表单验证可在chrome上正常运行。 但不能在Firefox中使用。
码:
<script type="text/javascript">
function validateForm()
{
var x=document.forms["newuserForm"]["mname"].value;
if (x==null || x=="")
{
alert("name must be filled");
return false;
}
var x=document.forms["newuserForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert(" email is not valid");
return false;
}
var x=document.forms["newuserForm"]["password"].value;
if (x==null || x=="")
{
alert("password must be filled out ");
return false;
}
/* var x=document.forms["newuserForm"]["age"].value;
if (x==null || x=="")
{
alert("Age must be Selected");
return false;
}*/
var m = document.getElementById('male');
var f = document.getElementById('female');
if ( (m.checked == false ) && (f.checked == false ) )
{
alert ( "Please select your gender ");
return false;
}
if( document.newuserForm.age.value == "-1" )
{
alert( "please select your age group" );
return false;
}
if( document.newuserForm.country.value == "-1" )
{
alert( "Please select your country");
return false;
}
if( document.newuserForm.city.value == "-1" )
{
alert( "please select your country" );
return false;
}
}
</script>
在chrome中,如果用户不输入名称,则会显示一条消息“必须填写名称”。 但是在Firefox中什么也没显示,如果我单击提交按钮而不输入名称,它将注册用户。 为什么Java脚本无法在Firefox上运行? 代码有什么问题?
试试这个代码,它也可以在Firefox
javascript中用于电子邮件验证的验证代码http://informationiswelth.blogspot.in/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.