J C
asked on
Help with javascript function
I am having a hard time getting this function to work correctly. I am new to javascript and am not sure where my error is.
What I am trying to accomplish:
Logic
If the actualenddate does not exist and the plannedenddate is in the future res=None
if the actualenddate does exist and it is greater than the plannedenddate res=Behind
if the actualenddate does not exist and the plannedenddate is < today res=Delinquent
if the actualenddate does exist and is <= plannedenddate res=Ahead
What I am trying to accomplish:
Logic
If the actualenddate does not exist and the plannedenddate is in the future res=None
if the actualenddate does exist and it is greater than the plannedenddate res=Behind
if the actualenddate does not exist and the plannedenddate is < today res=Delinquent
if the actualenddate does exist and is <= plannedenddate res=Ahead
function VerifyOnTime(actualEndDate,plannedEndDate){
//alert("actual: "+actualEndDate+" planned: "+plannedEndDate);
var res="NONE";
var ped=Date.parse(plannedEndDate);
var today=(new Date()).getTime();
var aed=null;
if (actualEndDate!='')
aed=Date.parse(actualEndDate);
else
aed=today;
if (aed!='' && aed>ped){
res='BEHIND';
}else if (ped>=today && aed==''){
res='NONE';
}else if (aed=='' && ped<today){
//alert(actualEndDate);
//alert(ped);
//alert(today);
res='DELINQUENT';
}else if (aed<=ped){
//alert(actualEndDate);
//alert(ped);
//alert(today);
res='AHEAD';
}else{
res='NONE';
}
//alert(res);
return res;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This worked perfectly. Thanks a lot!
something like this?
Sample:
http://jsfiddle.net/EE_RainerJ/c3zLJ/
Open in new window