M
mirkobonet
Hi,
I created two identical forms on the same page. I'd like to validate
only the one I'm in when I click submit.
I'm using the javascript
function MM_validateForm() { //v4.0
if (document.getElementById){
var
i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=document.getElementById(args);
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') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) 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'+errors);
document.MM_returnValue = (errors == '');
} }
and
<input type='submit'
onclick="MM_validateForm('Email_address','','RisEmail','Preferred_Phone_Number','','R');return
document.MM_returnValue" value='Submit'>
<input type='button' value='Cancel'
onClick="location.href='/';">
I add the form ID, but I don't know where to put in the script.
One solution would be rename all the fields with different names, but
I don't want to do that otherwise I need to change the php action
script too.
It should be a way to validate just a specific form, right?
Thanks all!
I created two identical forms on the same page. I'd like to validate
only the one I'm in when I click submit.
I'm using the javascript
function MM_validateForm() { //v4.0
if (document.getElementById){
var
i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=document.getElementById(args);
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') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) 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'+errors);
document.MM_returnValue = (errors == '');
} }
and
<input type='submit'
onclick="MM_validateForm('Email_address','','RisEmail','Preferred_Phone_Number','','R');return
document.MM_returnValue" value='Submit'>
<input type='button' value='Cancel'
onClick="location.href='/';">
I add the form ID, but I don't know where to put in the script.
One solution would be rename all the fields with different names, but
I don't want to do that otherwise I need to change the php action
script too.
It should be a way to validate just a specific form, right?
Thanks all!