Java脚本表单验证在chrome中工作良好,但在firefox中不工作
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/
相关文章:
- JavaScript获胜't运行,但在jsFiddle中工作
- Javascript的某些部分在Chrome中不起作用,但在其他浏览器中可以完美工作
- appendChild在函数外部工作,但在函数内部不工作
- 为什么这个jQuery可以作为一个小提琴工作,但在我的网页上没有
- Var工作,但在使用数组执行相同操作时停止
- jQuery REST会话没有'不工作,但在POSTMan工作
- 我的时间倒计时脚本在谷歌浏览器中工作正常,但在其他浏览器中打开时它显示为南楠
- 引导程序's的javascript在本地工作,但在部署到服务器时不能工作
- javascript代码,用于删除firefox中的空白,但在IE和chrome中无法正常工作
- 无法从IE中的data.responseText获取结果,但在其他浏览器中工作
- 复杂选择器在jQuery 1.8中中断,但在1.7.2中工作
- 意思是.js - 登录后重定向用户 - 在本地工作,但在部署时不起作用
- 火狐中的多个问题,但在 chrome 中工作正常,没有一个问题
- jQuery选择器在脚本中不起作用,但在控制台中工作
- 在键上验证正在工作,但在按键时它不起作用
- blur() 无法以编程方式工作 |但在从用户启动时会这样做
- 在暂存服务器中工作但在生产中失败的无效 URL
- 使用angular-google-maps指令在“grunt服务”期间工作.但在默认的grunt任务期间不会
- 将子项链接到在Chrome中工作但在Internet Explorer中不工作的按钮
- Blob createObjectURL下载在Firefox中不工作(但在调试时工作)