HDC
07-28-2008, 04:13 PM
I used an Excel to javascript converter to create an eloborate form. The problem is that I want to add in a seperate field validation script to my page but I have tried 3 different ones and all do not work. I get no javascript error as if the main script is over riding it. This converter that generated the script code is way over my head and make no since. Maybe this is simple for someone else so please let me know if its an obvious fix. Here is my script code.
<script language="javascript" type="text/javascript">
var co = new Object;
function recalc_onclick(ctl) {
if (true) {
co.Total_Cost=eeparseFloat(document.formc.Total_Cost.value);co.Plan=eeparsePercent(document.formc.Pl an.value);co.Provider1_Am
ount=eeparseFloat(document.formc.Provider1_Amount.value);co.Provider2_Amount=eeparseFloat(document.f ormc.Provider2_Amount.val
ue);co.Provider3_Amount=eeparseFloat(document.formc.Provider3_Amount.value);co.Total_Cost0=eeparseFl oat(document.formc.Total_
Cost0.value);co.Provider5_Amount=eeparseFloat(document.formc.Provider5_Amount.value);calc(co);docume nt.formc.Total_Fee.value=
eedisplayFloatND(co.Total_Fee,2);document.formc.Total_Posted.value=eedisplayFloatND(co.Total_Posted, 2);document.formc.Provide
r1_Fee.value=eedisplayFloat(co.Provider1_Fee);document.formc.Provider1_Net.value=eedisplayFloatND(co .Provider1_Net,2);documen
t.formc.Provider2_Fee.value=eedisplayFloat(co.Provider2_Fee);document.formc.Provider2_Net.value=eedi splayFloatND(co.Provider2
_Net,2);document.formc.Provider3_Fee.value=eedisplayFloat(co.Provider3_Fee);document.formc.Provider3 _Net.value=eedisplayFloat
ND(co.Provider3_Net,2);document.formc.Provider4_Fee.value=eedisplayFloat(co.Provider4_Fee);document. formc.Provider4_Net.value
=eedisplayFloatND(co.Provider4_Net,2);document.formc.Provider5_Fee.value=eedisplayFloat(co.Provider5 _Fee);document.formc.Prov
ider5_Net.value=eedisplayFloatND(co.Provider5_Net,2);document.formc.Total_Cost2.value=eedisplayFloat ND(co.Total_Cost2,2);docu
ment.formc.p1C12.value=eedisplayFloat(co.p1C12);document.formc.p1D12.value=eedisplayFloatND(co.p1D12 ,2);document.formc.Total_
Cost4.value=co.Total_Cost4;
};};
var eeisus=1;var eetrue="TRUE";var eefalse="FALSE";var eedec=".";var eeth=",";var eedecreg=new RegExp("\\.","g");var
eethreg=new RegExp(",","g");var eecurrencyreg=new RegExp("[$]","g");var eepercentreg=new RegExp("%","g");
var arr1xB7B11=new Array(5);for(var ii=0;ii<5;ii++){arr1xB7B11[ii]=new Array(1);for(var
jj=0;jj<1;jj++){arr1xB7B11[ii][jj]=0}};var arr1xC7C11=new Array(5);for(var ii=0;ii<5;ii++){arr1xC7C11[ii]=new
Array(1);for(var jj=0;jj<1;jj++){arr1xC7C11[ii][jj]=0}};var arr1xD7D11=new Array(5);for(var
ii=0;ii<5;ii++){arr1xD7D11[ii]=new Array(1);for(var jj=0;jj<1;jj++){arr1xD7D11[ii][jj]=0}};var eecm3=new Array(new
Array(arr1xB7B11,0,0,4,0));var eecm2=new Array(new Array(arr1xC7C11,0,0,4,0));var eecm1=new Array(new
Array(arr1xD7D11,0,0,4,0));function calc(data){var c1B1=data.Total_Cost;var
c1B2=data.Plan;arr1xB7B11[0][0]=data.Provider1_Amount;arr1xB7B11[1][0]=data.Provider2_Amount;arr1xB7B11[2][0]=data.Provider3_
Amount;arr1xB7B11[3][0]=data.Total_Cost0;arr1xB7B11[4][0]=data.Provider5_Amount;var c1B3=(((c1B1)*(c1B2)));var
c1B4=(((c1B1)-(c1B3)));arr1xC7C11[0][0]=(((arr1xB7B11[0][0])*(c1B2)));arr1xD7D11[0][0]=(((arr1xB7B11[0][0])-(arr1xC7C11[0][0]
)));arr1xC7C11[1][0]=(((arr1xB7B11[1][0])*(c1B2)));arr1xD7D11[1][0]=(((arr1xB7B11[1][0])-(arr1xC7C11[1][0])));arr1xC7C11[2][0
]=(((arr1xB7B11[2][0])*(c1B2)));arr1xD7D11[2][0]=(((arr1xB7B11[2][0])-(arr1xC7C11[2][0])));arr1xC7C11[3][0]=(((arr1xB7B11[3][
0])*(c1B2)));arr1xD7D11[3][0]=(((arr1xB7B11[3][0])-(arr1xC7C11[3][0])));arr1xC7C11[4][0]=(((arr1xB7B11[4][0])*(c1B2)));arr1xD
7D11[4][0]=(((arr1xB7B11[4][0])-(arr1xC7C11[4][0])));
var c1B12=(sumgeneral(5,0,0,eecm3));var c1B14=(((((c1B1)!=(c1B12)))?("Does Not Match Total Cost"):(" ")));var
c1C12=(sumgeneral(5,0,0,eecm2));var
c1D12=(sumgeneral(5,0,0,eecm1));data.Total_Fee=c1B3;data.Total_Posted=c1B4;data.Provider1_Fee=arr1xC 7C11[0][0];data.Provider1
_Net=arr1xD7D11[0][0];data.Provider2_Fee=arr1xC7C11[1][0];data.Provider2_Net=arr1xD7D11[1][0];data.Provider3_Fee=arr1xC7C11[2
][0];data.Provider3_Net=arr1xD7D11[2][0];data.Provider4_Fee=arr1xC7C11[3][0];data.Provider4_Net=arr1xD7D11[3][0];data.Provide
r5_Fee=arr1xC7C11[4][0];data.Provider5_Net=arr1xD7D11[4][0];data.Total_Cost2=c1B12;data.p1C12=c1C12;data.p1D12=c1D12;data.Tot
al_Cost4=c1B14;};
function myIsNaN(x){return(isNaN(x)||(typeof x=='number'&&!isFinite(x)));};function
round(n,nd){if(isFinite(n)&&isFinite(nd)){var sign_n=(n<0)?-1:1;var abs_n=Math.abs(n);var factor=Math.pow(10,nd);return
sign_n*Math.round(abs_n*factor)/factor;}else{return NaN;}};function sum2(arr,rt,rb){var sum=0;for(var
ii=rt;ii<=rb;ii++){sum+=arr[ii]};return sum};function sum3(arr,rt,ct,rb,cb){var sum=0;for(var ii=rt;ii<=rb;ii++){for(var
jj=ct;jj<=cb;jj++){sum+=arr[ii][jj]}};return sum};function sumgeneral(cnt,vsum,vcnt,x){var sum=vsum;for(var
ii=0;ii<x.length;ii++){sum+=sum3(x[ii][0],x[ii][1],x[ii][2],x[ii][3],x[ii][4]);};return sum;};function
eeparseFloat(str){str=String(str).replace(eedecreg,".");var res=parseFloat(str);if(isNaN(res)){return 0;}else{return
res;}};function eeparsePercent(str){var parts=String(str).split('%');var tmp=String(parts[0]).replace(eedecreg,".");var
res=parseFloat(tmp)/100;if(isNaN(res)){return 0;}else{return res;}};var near0RegExp=new
RegExp("[.](.*0000000|.*9999999)");function eedisplayFloat(x){if(myIsNaN(x)){return Number.NaN;}else{var
str=String(x);if(near0RegExp.test(str)){x=round(x,8);str=String(x);}return str.replace(/\./g,eedec);}};function
eedisplayFloatND(x,nd){if(myIsNaN(x)){return Number.NaN;}else{var res=round(x,nd);if(nd>0){var
str=String(res);if(str.indexOf('e')!=-1)return str;if(str.indexOf('E')!=-1)return str;var
parts=str.split('.');if(parts.length<2){var
decimals=('00000000000000').substring(0,nd);return(parts[0]).toString()+eedec+decimals;}else{var
decimals=((parts[1]).toString()+'00000000000000').substring(0,nd);return(parts[0]).toString()+eedec+decimals;}}else{return
res;}}};
function eedisplayPercentND(x,nd){if(myIsNaN(x)){return Number.NaN;}else{return eedisplayFloatND(x*100,nd)+'%';}}
</script>
</head>
<body onload="initial_update();document.formc.Total_Cost.focus();document.formc.Total_Cost.select();">
<form id="formc" name="formc" method="post" action="/MIS/CCC.pl">
Here is the validation script I'm trying to use also.
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkFields() {
missinginfo = "";
if (document.formc.Office_ID.value == "") {
missinginfo += "\n - Office Name";
}
if (document.formc.Prod_Ins.value == "") {
missinginfo += "\n - Production";
}
if (document.formc.Total_Deposits.value == "") {
missinginfo += "\n - Total Deposit";
}
if (document.formc.Took_Deposit.value == "") {
missinginfo += "\n - Person Taking Deposit";
}
if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else return true;
}
// End -->
</script>
<script language="javascript" type="text/javascript">
var co = new Object;
function recalc_onclick(ctl) {
if (true) {
co.Total_Cost=eeparseFloat(document.formc.Total_Cost.value);co.Plan=eeparsePercent(document.formc.Pl an.value);co.Provider1_Am
ount=eeparseFloat(document.formc.Provider1_Amount.value);co.Provider2_Amount=eeparseFloat(document.f ormc.Provider2_Amount.val
ue);co.Provider3_Amount=eeparseFloat(document.formc.Provider3_Amount.value);co.Total_Cost0=eeparseFl oat(document.formc.Total_
Cost0.value);co.Provider5_Amount=eeparseFloat(document.formc.Provider5_Amount.value);calc(co);docume nt.formc.Total_Fee.value=
eedisplayFloatND(co.Total_Fee,2);document.formc.Total_Posted.value=eedisplayFloatND(co.Total_Posted, 2);document.formc.Provide
r1_Fee.value=eedisplayFloat(co.Provider1_Fee);document.formc.Provider1_Net.value=eedisplayFloatND(co .Provider1_Net,2);documen
t.formc.Provider2_Fee.value=eedisplayFloat(co.Provider2_Fee);document.formc.Provider2_Net.value=eedi splayFloatND(co.Provider2
_Net,2);document.formc.Provider3_Fee.value=eedisplayFloat(co.Provider3_Fee);document.formc.Provider3 _Net.value=eedisplayFloat
ND(co.Provider3_Net,2);document.formc.Provider4_Fee.value=eedisplayFloat(co.Provider4_Fee);document. formc.Provider4_Net.value
=eedisplayFloatND(co.Provider4_Net,2);document.formc.Provider5_Fee.value=eedisplayFloat(co.Provider5 _Fee);document.formc.Prov
ider5_Net.value=eedisplayFloatND(co.Provider5_Net,2);document.formc.Total_Cost2.value=eedisplayFloat ND(co.Total_Cost2,2);docu
ment.formc.p1C12.value=eedisplayFloat(co.p1C12);document.formc.p1D12.value=eedisplayFloatND(co.p1D12 ,2);document.formc.Total_
Cost4.value=co.Total_Cost4;
};};
var eeisus=1;var eetrue="TRUE";var eefalse="FALSE";var eedec=".";var eeth=",";var eedecreg=new RegExp("\\.","g");var
eethreg=new RegExp(",","g");var eecurrencyreg=new RegExp("[$]","g");var eepercentreg=new RegExp("%","g");
var arr1xB7B11=new Array(5);for(var ii=0;ii<5;ii++){arr1xB7B11[ii]=new Array(1);for(var
jj=0;jj<1;jj++){arr1xB7B11[ii][jj]=0}};var arr1xC7C11=new Array(5);for(var ii=0;ii<5;ii++){arr1xC7C11[ii]=new
Array(1);for(var jj=0;jj<1;jj++){arr1xC7C11[ii][jj]=0}};var arr1xD7D11=new Array(5);for(var
ii=0;ii<5;ii++){arr1xD7D11[ii]=new Array(1);for(var jj=0;jj<1;jj++){arr1xD7D11[ii][jj]=0}};var eecm3=new Array(new
Array(arr1xB7B11,0,0,4,0));var eecm2=new Array(new Array(arr1xC7C11,0,0,4,0));var eecm1=new Array(new
Array(arr1xD7D11,0,0,4,0));function calc(data){var c1B1=data.Total_Cost;var
c1B2=data.Plan;arr1xB7B11[0][0]=data.Provider1_Amount;arr1xB7B11[1][0]=data.Provider2_Amount;arr1xB7B11[2][0]=data.Provider3_
Amount;arr1xB7B11[3][0]=data.Total_Cost0;arr1xB7B11[4][0]=data.Provider5_Amount;var c1B3=(((c1B1)*(c1B2)));var
c1B4=(((c1B1)-(c1B3)));arr1xC7C11[0][0]=(((arr1xB7B11[0][0])*(c1B2)));arr1xD7D11[0][0]=(((arr1xB7B11[0][0])-(arr1xC7C11[0][0]
)));arr1xC7C11[1][0]=(((arr1xB7B11[1][0])*(c1B2)));arr1xD7D11[1][0]=(((arr1xB7B11[1][0])-(arr1xC7C11[1][0])));arr1xC7C11[2][0
]=(((arr1xB7B11[2][0])*(c1B2)));arr1xD7D11[2][0]=(((arr1xB7B11[2][0])-(arr1xC7C11[2][0])));arr1xC7C11[3][0]=(((arr1xB7B11[3][
0])*(c1B2)));arr1xD7D11[3][0]=(((arr1xB7B11[3][0])-(arr1xC7C11[3][0])));arr1xC7C11[4][0]=(((arr1xB7B11[4][0])*(c1B2)));arr1xD
7D11[4][0]=(((arr1xB7B11[4][0])-(arr1xC7C11[4][0])));
var c1B12=(sumgeneral(5,0,0,eecm3));var c1B14=(((((c1B1)!=(c1B12)))?("Does Not Match Total Cost"):(" ")));var
c1C12=(sumgeneral(5,0,0,eecm2));var
c1D12=(sumgeneral(5,0,0,eecm1));data.Total_Fee=c1B3;data.Total_Posted=c1B4;data.Provider1_Fee=arr1xC 7C11[0][0];data.Provider1
_Net=arr1xD7D11[0][0];data.Provider2_Fee=arr1xC7C11[1][0];data.Provider2_Net=arr1xD7D11[1][0];data.Provider3_Fee=arr1xC7C11[2
][0];data.Provider3_Net=arr1xD7D11[2][0];data.Provider4_Fee=arr1xC7C11[3][0];data.Provider4_Net=arr1xD7D11[3][0];data.Provide
r5_Fee=arr1xC7C11[4][0];data.Provider5_Net=arr1xD7D11[4][0];data.Total_Cost2=c1B12;data.p1C12=c1C12;data.p1D12=c1D12;data.Tot
al_Cost4=c1B14;};
function myIsNaN(x){return(isNaN(x)||(typeof x=='number'&&!isFinite(x)));};function
round(n,nd){if(isFinite(n)&&isFinite(nd)){var sign_n=(n<0)?-1:1;var abs_n=Math.abs(n);var factor=Math.pow(10,nd);return
sign_n*Math.round(abs_n*factor)/factor;}else{return NaN;}};function sum2(arr,rt,rb){var sum=0;for(var
ii=rt;ii<=rb;ii++){sum+=arr[ii]};return sum};function sum3(arr,rt,ct,rb,cb){var sum=0;for(var ii=rt;ii<=rb;ii++){for(var
jj=ct;jj<=cb;jj++){sum+=arr[ii][jj]}};return sum};function sumgeneral(cnt,vsum,vcnt,x){var sum=vsum;for(var
ii=0;ii<x.length;ii++){sum+=sum3(x[ii][0],x[ii][1],x[ii][2],x[ii][3],x[ii][4]);};return sum;};function
eeparseFloat(str){str=String(str).replace(eedecreg,".");var res=parseFloat(str);if(isNaN(res)){return 0;}else{return
res;}};function eeparsePercent(str){var parts=String(str).split('%');var tmp=String(parts[0]).replace(eedecreg,".");var
res=parseFloat(tmp)/100;if(isNaN(res)){return 0;}else{return res;}};var near0RegExp=new
RegExp("[.](.*0000000|.*9999999)");function eedisplayFloat(x){if(myIsNaN(x)){return Number.NaN;}else{var
str=String(x);if(near0RegExp.test(str)){x=round(x,8);str=String(x);}return str.replace(/\./g,eedec);}};function
eedisplayFloatND(x,nd){if(myIsNaN(x)){return Number.NaN;}else{var res=round(x,nd);if(nd>0){var
str=String(res);if(str.indexOf('e')!=-1)return str;if(str.indexOf('E')!=-1)return str;var
parts=str.split('.');if(parts.length<2){var
decimals=('00000000000000').substring(0,nd);return(parts[0]).toString()+eedec+decimals;}else{var
decimals=((parts[1]).toString()+'00000000000000').substring(0,nd);return(parts[0]).toString()+eedec+decimals;}}else{return
res;}}};
function eedisplayPercentND(x,nd){if(myIsNaN(x)){return Number.NaN;}else{return eedisplayFloatND(x*100,nd)+'%';}}
</script>
</head>
<body onload="initial_update();document.formc.Total_Cost.focus();document.formc.Total_Cost.select();">
<form id="formc" name="formc" method="post" action="/MIS/CCC.pl">
Here is the validation script I'm trying to use also.
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkFields() {
missinginfo = "";
if (document.formc.Office_ID.value == "") {
missinginfo += "\n - Office Name";
}
if (document.formc.Prod_Ins.value == "") {
missinginfo += "\n - Production";
}
if (document.formc.Total_Deposits.value == "") {
missinginfo += "\n - Total Deposit";
}
if (document.formc.Took_Deposit.value == "") {
missinginfo += "\n - Person Taking Deposit";
}
if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else return true;
}
// End -->
</script>