Thank you in advance for the help.
I have 2 separate forms on one main page
one is for Adding the other is to update a list of employees. The reason i did this was to validate the information client side using the Yaromat add on behavior each of them have their own submit buttons.
Question #1
The JS validation only works with the add on submit button and does not work with the update? Any help?
Question #2
When validating and updating server side im having trouble with the action page. I can not seem to pass the form values for that specific form. HOw do you pass/call a specific form? ex with 1 form it would be something like Form.addID but with multiple forms i can not seem to pass it properly for validation.
I new to Cold fusion so I apologize if this is a too complex of a question and the length of it But I appricate any guidence you can give me. Thank you for your time and consideration!!!
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--- This is the JS Yaromat automatically creates--->
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"
)>0&&parent.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.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById
; return x;
}
function YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
for (var i=1; i<args.length;i=i+4){
if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
var myObj = MM_findObj(args.replace(/\[\d+\]/ig,""
);
myV=myObj.value;
if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
if (myReq&&myObj.value.length==0){addErr=true}
if ((myV.length>0)&&(args[i+2]==1)){ //fromto
var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
} else if ((myV.length>0)&&(args[i+2]==2)){
var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$"
;if(!rx.test(myV))addErr=true;
} else if ((myV.length>0)&&(args[i+2]==3)){ // date
var myMa=args[i+1].split("#"
; var myAt=myV.match(myMa[0]);
if(myAt){
var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
var myDate=new Date(myY,myM,myD);
if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
}else{addErr=true}
} else if ((myV.length>0)&&(args[i+2]==4)){ // time
var myMa=args[i+1].split("#"
; var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
} else if (myV.length>0&&args[i+2]==5){ // check this 2
var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""
);
if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,""
];
if(!myObj1.checked){addErr=true}
} else if (myV.length>0&&args[i+2]==6){ // the same
var myObj1 = MM_findObj(args[i+1]);
if(myV!=myObj1.value){addErr=true}
}
} else
if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
var myTest = args.match(/(.*)\[(\d+)\].*/i);
var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
if (args[i+2]==2){
var myDot=false;
for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
if(!myDot){myErr+='* ' +args[i+3]+'\n'}
}
} else if (myObj.type=='checkbox'){
if(args[i+2]==1&&myObj.checked==false){addErr=true}
if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
} else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
}else if (myObj.type=='textarea'){
if(myV.length<args[i+1]){addErr=true}
}
if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
}
if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
document.MM_returnValue = (myErr=='');
}
//-->
</script>
</head>
<body onLoad="clock()">
<cfset EditMode=IsDefined("url.ID"
>
<cfif EditMode>
<cfquery datasource="Table" name="Employees_edit">
Select *
From Process
Where ID=#url.ID#
</cfquery>
</cfif>
<cfquery datasource="table" name="Employees">
Select *
From Process
Order By ID
</cfquery>
<h1 align="center">Employee List</h1>
<table align="center" width="75%" border="1">
<tr bgcolor="#CCCCCC">
<td width="18%"><div align="center"><font color="#0000FF">ID</font></div></td>
<td width="51%"><div align="center"><font color="#0000FF">Employee</font></div></td>
<td width="15%"><div align="center"><font color="#0000FF">Edit</font></div></td>
<td width="16%"><div align="center"><font color="#0000FF">Delete</font></div></td>
</tr>
<cfoutput query="Employees">
<cfif CurrentRow MOD 2 is 1>
<cfset bgcolor="lime">
<cfelse>
<cfset bgcolor="white">
</cfif>
<cfif EditMode>
<cfif #ID# eq #URL.ID#>
<tr bgcolor="#bgcolor#">
<form action="action.cfm" method="post" name="myform2" onSubmit="YY_checkform('myform2','editID','##q','0','Field \'editID\' is not valid.','editname','##q','0','Field \'editname\' is not valid.');return document.MM_returnValue"">
<td>
<input name="editID" type="text" value="#ID#" size="10"
MaxLength="10"
Required="yes"> </td>
<td>
<input name="editname" type="text" value="#name#"
size="30"
MaxLength="30" equired="yes"> </td>
<td div align="center">
<input name="update" type="submit" value="update">
</div></td>
<td div align="center">
<input name="Cancel" type="reset" id="Cancel" value="Cancel">
</div></td>
</tr>
</form>
<cfelse>
<tr bgcolor="#bgcolor#">
<td><div align="center"><b>#ID#</b></div></td>
<td><div align="left"><b>#name#</b></div></td>
<td><div align="center"><a href="employeecurrent2a.cfm?ID=#urlEncodedFormat(Trim(ID))#">Edit</a></div></td>
<td><div align="center"><a href="employee_delete.cfm?ID=#ID#">Delete</a></div></td>
</tr>
</cfif>
<cfelse>
<tr bgcolor="#bgcolor#">
<td><div align="center"><b>#ID#</b></div></td>
<td><div align="left"><b>#name#</b></div></td>
<td><div align="center"><a href="employeev2a.cfm?ID=#urlEncodedFormat(Trim(ID))#">Edit</a></div></td>
<td><div align="center"><a href="employee_delete.cfm?ID=#ID#">Delete</a></div></td>
</tr>
</cfif>
</cfoutput>
<cfoutput>
<cfif not EditMode>
<tr>
<td>
<form action="action.cfm" name="myform" onSubmit="YY_checkform('myform','addID','##1_100','1','Field \'addID\' is not valid.','addName','##q','0','Field \'addName\' is not valid.');return document.MM_returnValue">
<input name="addID" type="text"
MaxLength="10"
Required="yes"
Message="ID is Required!"
Validate="integer"> </td>
<td> <input name="addName" type="text"
size="30"
MaxLength="30">
</td>
<td colspan="2"> <div align="center">
<input name="Add" type="submit" value="Add" >
</form>
</div></td>
</tr>
</cfif></cfoutput>
</body>
</html>
<!---Action.cfm--->
<cfquery datasource="table" name="check_record">
Select ID
From Process
Where ID=#Form.addID#
</cfquery>
<cfif ISDefined("Form.update"
>
<Cfif Len(Trim(editname)) is 0>
<h2> Error! Name can not be Blank!</h2>
<cfelse>
<cfquery datasource="table">
Update Process
Set name='#Trim(Form.editname)#'
Where id=#Form.editID#
</cfquery>
<cflocation url="Employee---.cfm"></cfif>
</cfif>
<cfif ISDefined("Form.Add"
>
<cfif Len(Trim(addname)) eq 0>
<h2> Error! Name can not be Blank!</h2>
<cfelseif len(trim(addID)) eq 0>
<h2>Error! ID can not be Blank!</h2>
<cfabort>
<cfelseif IsNumeric(addID) is "no">
<h2> Error! ID must be numeric!</h2>
<cfabort>
<cfelseif check_record.RecordCount eq '0'>
<cfquery datasource="table" name="insert_record">
Insert into Process (ID, name)
Values ('#Trim(Form.ID)#',
'#Trim(Form.name)#')
</cfquery>
<cflocation url="Employee---.cfm">
<cfelse>
This Record already exists!
</cfif>
<cfelse>
Wrong
</cfif>
<cfif ISDefined("Form.Cancel"
>
what
<cfelse>
fsf<cflocation url="Employee---.cfm">
</cfif>
I have 2 separate forms on one main page
one is for Adding the other is to update a list of employees. The reason i did this was to validate the information client side using the Yaromat add on behavior each of them have their own submit buttons.
Question #1
The JS validation only works with the add on submit button and does not work with the update? Any help?
Question #2
When validating and updating server side im having trouble with the action page. I can not seem to pass the form values for that specific form. HOw do you pass/call a specific form? ex with 1 form it would be something like Form.addID but with multiple forms i can not seem to pass it properly for validation.
I new to Cold fusion so I apologize if this is a too complex of a question and the length of it But I appricate any guidence you can give me. Thank you for your time and consideration!!!
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--- This is the JS Yaromat automatically creates--->
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"
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.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById
}
function YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
for (var i=1; i<args.length;i=i+4){
if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
var myObj = MM_findObj(args.replace(/\[\d+\]/ig,""
myV=myObj.value;
if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
if (myReq&&myObj.value.length==0){addErr=true}
if ((myV.length>0)&&(args[i+2]==1)){ //fromto
var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
} else if ((myV.length>0)&&(args[i+2]==2)){
var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$"
} else if ((myV.length>0)&&(args[i+2]==3)){ // date
var myMa=args[i+1].split("#"
if(myAt){
var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
var myDate=new Date(myY,myM,myD);
if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
}else{addErr=true}
} else if ((myV.length>0)&&(args[i+2]==4)){ // time
var myMa=args[i+1].split("#"
} else if (myV.length>0&&args[i+2]==5){ // check this 2
var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""
if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,""
if(!myObj1.checked){addErr=true}
} else if (myV.length>0&&args[i+2]==6){ // the same
var myObj1 = MM_findObj(args[i+1]);
if(myV!=myObj1.value){addErr=true}
}
} else
if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
var myTest = args.match(/(.*)\[(\d+)\].*/i);
var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
if (args[i+2]==2){
var myDot=false;
for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
if(!myDot){myErr+='* ' +args[i+3]+'\n'}
}
} else if (myObj.type=='checkbox'){
if(args[i+2]==1&&myObj.checked==false){addErr=true}
if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
} else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
}else if (myObj.type=='textarea'){
if(myV.length<args[i+1]){addErr=true}
}
if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
}
if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
document.MM_returnValue = (myErr=='');
}
//-->
</script>
</head>
<body onLoad="clock()">
<cfset EditMode=IsDefined("url.ID"
<cfif EditMode>
<cfquery datasource="Table" name="Employees_edit">
Select *
From Process
Where ID=#url.ID#
</cfquery>
</cfif>
<cfquery datasource="table" name="Employees">
Select *
From Process
Order By ID
</cfquery>
<h1 align="center">Employee List</h1>
<table align="center" width="75%" border="1">
<tr bgcolor="#CCCCCC">
<td width="18%"><div align="center"><font color="#0000FF">ID</font></div></td>
<td width="51%"><div align="center"><font color="#0000FF">Employee</font></div></td>
<td width="15%"><div align="center"><font color="#0000FF">Edit</font></div></td>
<td width="16%"><div align="center"><font color="#0000FF">Delete</font></div></td>
</tr>
<cfoutput query="Employees">
<cfif CurrentRow MOD 2 is 1>
<cfset bgcolor="lime">
<cfelse>
<cfset bgcolor="white">
</cfif>
<cfif EditMode>
<cfif #ID# eq #URL.ID#>
<tr bgcolor="#bgcolor#">
<form action="action.cfm" method="post" name="myform2" onSubmit="YY_checkform('myform2','editID','##q','0','Field \'editID\' is not valid.','editname','##q','0','Field \'editname\' is not valid.');return document.MM_returnValue"">
<td>
<input name="editID" type="text" value="#ID#" size="10"
MaxLength="10"
Required="yes"> </td>
<td>
<input name="editname" type="text" value="#name#"
size="30"
MaxLength="30" equired="yes"> </td>
<td div align="center">
<input name="update" type="submit" value="update">
</div></td>
<td div align="center">
<input name="Cancel" type="reset" id="Cancel" value="Cancel">
</div></td>
</tr>
</form>
<cfelse>
<tr bgcolor="#bgcolor#">
<td><div align="center"><b>#ID#</b></div></td>
<td><div align="left"><b>#name#</b></div></td>
<td><div align="center"><a href="employeecurrent2a.cfm?ID=#urlEncodedFormat(Trim(ID))#">Edit</a></div></td>
<td><div align="center"><a href="employee_delete.cfm?ID=#ID#">Delete</a></div></td>
</tr>
</cfif>
<cfelse>
<tr bgcolor="#bgcolor#">
<td><div align="center"><b>#ID#</b></div></td>
<td><div align="left"><b>#name#</b></div></td>
<td><div align="center"><a href="employeev2a.cfm?ID=#urlEncodedFormat(Trim(ID))#">Edit</a></div></td>
<td><div align="center"><a href="employee_delete.cfm?ID=#ID#">Delete</a></div></td>
</tr>
</cfif>
</cfoutput>
<cfoutput>
<cfif not EditMode>
<tr>
<td>
<form action="action.cfm" name="myform" onSubmit="YY_checkform('myform','addID','##1_100','1','Field \'addID\' is not valid.','addName','##q','0','Field \'addName\' is not valid.');return document.MM_returnValue">
<input name="addID" type="text"
MaxLength="10"
Required="yes"
Message="ID is Required!"
Validate="integer"> </td>
<td> <input name="addName" type="text"
size="30"
MaxLength="30">
</td>
<td colspan="2"> <div align="center">
<input name="Add" type="submit" value="Add" >
</form>
</div></td>
</tr>
</cfif></cfoutput>
</body>
</html>
<!---Action.cfm--->
<cfquery datasource="table" name="check_record">
Select ID
From Process
Where ID=#Form.addID#
</cfquery>
<cfif ISDefined("Form.update"
<Cfif Len(Trim(editname)) is 0>
<h2> Error! Name can not be Blank!</h2>
<cfelse>
<cfquery datasource="table">
Update Process
Set name='#Trim(Form.editname)#'
Where id=#Form.editID#
</cfquery>
<cflocation url="Employee---.cfm"></cfif>
</cfif>
<cfif ISDefined("Form.Add"
<cfif Len(Trim(addname)) eq 0>
<h2> Error! Name can not be Blank!</h2>
<cfelseif len(trim(addID)) eq 0>
<h2>Error! ID can not be Blank!</h2>
<cfabort>
<cfelseif IsNumeric(addID) is "no">
<h2> Error! ID must be numeric!</h2>
<cfabort>
<cfelseif check_record.RecordCount eq '0'>
<cfquery datasource="table" name="insert_record">
Insert into Process (ID, name)
Values ('#Trim(Form.ID)#',
'#Trim(Form.name)#')
</cfquery>
<cflocation url="Employee---.cfm">
<cfelse>
This Record already exists!
</cfif>
<cfelse>
Wrong
</cfif>
<cfif ISDefined("Form.Cancel"
what
<cfelse>
fsf<cflocation url="Employee---.cfm">
</cfif>