这是我的表格:
function formValidator(){
var a = document.getElementById('uname');
var b = document.getElementById('m_photo');
var c= document.getElementById('fname');
var d= document.getElementById('lname');
var e= document.getElementById('p_add');
var f= document.getElementById('c_add');
var g= document.getElementById('b_add');
var h= document.getElementById('country');
var i= document.getElementById('state');
var j= document.getElementById('city');
var k= document.getElementById('pcode');
var l= document.getElementById('id_proof');
var m= document.getElementById('quali_proof');
var n= document.getElementById('p_addproof');
var o= document.getElementById('c_addproof');
var p= document.getElementById('resume');
var q= document.getElementById('dob');
var r= document.getElementById('mobile');
var s= document.getElementById('email');
var t= document.getElementById('quali');
var u= document.getElementById('dsgn');
var v= document.getElementById('rep_person');
var w= document.getElementById('join');
var x= document.getElementById('p_hist');
var y= document.getElementById('sh_des');
var z= document.getElementById('app_by');
var A= document.getElementById('accept');
// Check each input in the order that it appears in the form!
if(lengthRestriction(a, 6, 8)){
if(""==b.value)
{alert("Please Upload the Member Photo");
if(isAlphabet(c, "Please enter only Alphabets for First Name")){
if(isAlphabet(d, "Please enter only Alphabets for Last Name")){
if(e==null || e=="")
{alert("Please Enter your Permanent Address");
if(f==null || f=="")
{alert("Please Enter your Current Address");
if(g==null || g=="")
{alert("Please Enter your Branch Address");
if(h==null || h=="")
{alert("Please Enter the Country Name");
if(i==null || i=="")
{alert("Please Enter the State Name");
if(j==null || j=="")
{alert("Please Enter the City Name");
//if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
if(isNumeric(k, "Please enter a valid 6 digit Pin Code")){
if(l==null || l=="")
{alert("Please Upload the Id-Proof");
if(m==null || m=="")
{alert("Please Upload the Qualification Proof");
if(n==null || n=="")
{alert("Please Upload the Permanent Address Proof");
if(o==null || o=="")
{alert("Please Upload the Current Address Proof");
if(p==null || p=="")
{alert("Please Upload the Resume");
if(q==null || q=="")
{alert("Please Upload the D.O.B Proof");
if(lengthRestriction(r,10,10)){
if(emailValidator(s, "Please enter a valid email address")){
if(t==null || t=="")
{alert("Please Enter the Qualification Details");
if(madeSelection(u, "Please Choose a Designation")){
if(v==null || v=="")
{alert("Please Enter the name of the Reporting Person");
if(w==null || w=="")
{alert("Please Enter the Joining Date");
if(x==null || x=="")
{alert("Please Write Something about Past History");
if(y==null || y=="")
{alert("Please give some Description about the Member");
if(z==null || z=="")
{alert("Empty Field: APPOINTED BY");
if(madeSelection(A, "Please Accept the terms and conditions")){
return true;
}}
}}
}}
}}
}}
}}
}}
}}
}}
}}
}}
}}
}}
}
return false;
}
function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}
function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function isAlphanumeric(elem, helperMsg){
var alphaExp = /^[0-9a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function lengthRestriction(elem, min, max){
var uInput = elem.value;
if(uInput.length >= min && uInput.length <= max){
return true;
}else{
alert("Please enter between " +min+ " and " +max+ " characters");
elem.focus();
return false;
}
}
function madeSelection(elem, helperMsg){
if(elem.value == "Select Designation"){
alert(helperMsg);
elem.focus();
return false;
}else
{
return true;
}
}
function emailValidator(elem, helperMsg){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
此处仅对前两种情况进行验证。我无法弄清楚问题所在。任何人都可以帮忙吗?
在用户移动到下一个字段之前,我需要验证当前字段,因此所有 if 语句都嵌套以遵循特定顺序。
另外,我希望将表单数据重定向到另一个文件。我用过action="abc.html"
(例如)。单击提交按钮时,它直接转到abc.html
而不是验证表单数据。