Here is some javascript checking I have for form validation. The
problem is is that it loops..... How can I make it stop ? IF I click
on the last name text box, it scolds me, saying the first_name needs
to be filled out. I click ok, and it says the last_name needs to be
filled out...i click ok and it says the first_name needs to be
filled.. wash rinse repeat !!!!
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf ("?"))>0&&paren t.frames.length ) {
d=parent.frames[n.substring(p+1 )].document; n=n.substring(0 ,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.fo rms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.l ayers&&i<d.laye rs.length;i++)
x=MM_findObj(n, d.layers[i].document);
if(!x && document.getEle mentById) x=document.getE lementById(n);
return x;
}
function MM_validateForm () { //v4.0
var i,p,q,nm,test,n um,min,max,erro rs='',args=MM_v alidateForm.arg uments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=MM_findObj( args[i]);
if (val) { nm=val.name; if ((val=val.value )!="") {
if (test.indexOf(' isEmail')!=-1) { p=val.indexOf(' @');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain
an e-mail address.\n';
} else if (test!='R') {
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf(' inRange') != -1) { p=test.indexOf( ':');
min=test.substr ing(8,p); max=test.substr ing(p+1);
if (val<min || max<val) errors+='- '+nm+' must contain a
number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is
required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+er rors);
document.MM_ret urnValue = (errors == '');
document.forms['form0'][nm].focus();
}
<form name="form0" method="post" action="palm-beta.asp?action =add">
<table class="table_co ntent" border="0" cellpadding="3"
cellspacing="0" >
<tr class="box_left "><td><b>Fi rst Name</b></td></tr>
<tr class="box_righ t"><td><inpu t type="textbox" name="First_Nam e"
maxlength="20" size="21"
onBlur="MM_vali dateForm('First _Name','','R'); return
document.MM_ret urnValue"></td></tr>
<tr class="box_left "><td><b>La st Name</b></td></tr>
<tr class="box_righ t"><td><inpu t type="text" Name="Last_Name "
maxlength="20" size="21"
onBlur="MM_vali dateForm('Last_ Name','','R');r eturn
document.MM_ret urnValue"></td></tr>
<tr class="box_left "><td><b>Em ail Address</b></td></tr>
<tr class="box_righ t"><td><inpu t type="text" Name="Email_Add ress"
maxlength="50" size="51"
onBlur="MM_vali dateForm('Email _Address','','R isEmail');retur n
document.MM_ret urnValue"></td></tr>
<tr class="box_info "><td>  ;</td></tr>
<tr class="box_info "><td><inpu t type="submit" name="addemail"
value="Submit" class="button"> </td></tr>
</table>
</form>
problem is is that it loops..... How can I make it stop ? IF I click
on the last name text box, it scolds me, saying the first_name needs
to be filled out. I click ok, and it says the last_name needs to be
filled out...i click ok and it says the first_name needs to be
filled.. wash rinse repeat !!!!
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf ("?"))>0&&paren t.frames.length ) {
d=parent.frames[n.substring(p+1 )].document; n=n.substring(0 ,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.fo rms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.l ayers&&i<d.laye rs.length;i++)
x=MM_findObj(n, d.layers[i].document);
if(!x && document.getEle mentById) x=document.getE lementById(n);
return x;
}
function MM_validateForm () { //v4.0
var i,p,q,nm,test,n um,min,max,erro rs='',args=MM_v alidateForm.arg uments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=MM_findObj( args[i]);
if (val) { nm=val.name; if ((val=val.value )!="") {
if (test.indexOf(' isEmail')!=-1) { p=val.indexOf(' @');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain
an e-mail address.\n';
} else if (test!='R') {
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf(' inRange') != -1) { p=test.indexOf( ':');
min=test.substr ing(8,p); max=test.substr ing(p+1);
if (val<min || max<val) errors+='- '+nm+' must contain a
number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is
required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+er rors);
document.MM_ret urnValue = (errors == '');
document.forms['form0'][nm].focus();
}
<form name="form0" method="post" action="palm-beta.asp?action =add">
<table class="table_co ntent" border="0" cellpadding="3"
cellspacing="0" >
<tr class="box_left "><td><b>Fi rst Name</b></td></tr>
<tr class="box_righ t"><td><inpu t type="textbox" name="First_Nam e"
maxlength="20" size="21"
onBlur="MM_vali dateForm('First _Name','','R'); return
document.MM_ret urnValue"></td></tr>
<tr class="box_left "><td><b>La st Name</b></td></tr>
<tr class="box_righ t"><td><inpu t type="text" Name="Last_Name "
maxlength="20" size="21"
onBlur="MM_vali dateForm('Last_ Name','','R');r eturn
document.MM_ret urnValue"></td></tr>
<tr class="box_left "><td><b>Em ail Address</b></td></tr>
<tr class="box_righ t"><td><inpu t type="text" Name="Email_Add ress"
maxlength="50" size="51"
onBlur="MM_vali dateForm('Email _Address','','R isEmail');retur n
document.MM_ret urnValue"></td></tr>
<tr class="box_info "><td>  ;</td></tr>
<tr class="box_info "><td><inpu t type="submit" name="addemail"
value="Submit" class="button"> </td></tr>
</table>
</form>
Comment