简体   繁体   English

Java脚本形式验证在Chrome中正常工作,但不能在Firefox中工作?

[英]java script form validation works fine in chrome but not working in firefox?

form validation using java script works fine on chrome. 使用Java脚本进行表单验证可在chrome上正常运行。 but not working in firefox. 但不能在Firefox中使用。

Code: 码:

<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>

in chrome if the user doesn't enter name, it will shows a message "name must be filled". 在chrome中,如果用户不输入名称,则会显示一条消息“必须填写名称”。 but in Firefox nothing shows, if i click the submit button without entering the name it will registering the user. 但是在Firefox中什么也没显示,如果我单击提交按钮而不输入名称,它将注册用户。 why the java script not working on Firefox? 为什么Java脚本无法在Firefox上运行? whats wrong with the code? 代码有什么问题?

try this code it is working in firefox also 试试这个代码,它也可以在Firefox

validation code in javascript for email validation http://informationiswelth.blogspot.in/ javascript中用于电子邮件验证的验证代码http://informationiswelth.blogspot.in/

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

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