Java脚本表单验证在chrome中工作良好,但在firefox中不工作

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

本文关键字:工作 但在 firefox 脚本 验证 chrome Java 表单      更新时间:2023-09-26

使用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/

相关文章: