Copy link to clipboard
Copied
Hi,
I am working on a PDF in Acrobat Pro DC and need some help with some JS that is eluding me. I am trying to make the text color change based on an expiration date. If the date is today or earlier to change text to red. otherwise black.
Here is what i have at the moment put in the custom calculation script, i have tried many different versions i just cant get it to work. I cant seem to find anything anywhere on line for this.
Any assistance is greatful on where i could be going wrong.
var Date = util.printd("dd-mmm-yyyy", new Date());
if (event.value.date <= Date)
{
event.target.textColor = color.red;
}
else
{
event.target.textColor = color.black;
}
A couple of issues there:
1. Don't name a variable "Date". There's a built-in object with that name and you'll get conflicts between them.
2. There's no such thing as "event.value.date". If by that you mean that you want to use the value the user entered then you need to access event.value, convert it to a Date object (using util.scand) and then you'll be able to compare it to another Date object.
Copy link to clipboard
Copied
A couple of issues there:
1. Don't name a variable "Date". There's a built-in object with that name and you'll get conflicts between them.
2. There's no such thing as "event.value.date". If by that you mean that you want to use the value the user entered then you need to access event.value, convert it to a Date object (using util.scand) and then you'll be able to compare it to another Date object.
Copy link to clipboard
Copied
Hi,
Thanks, the util.scand is what i was after. util.printd was not quite as it was converting to a string from a date which messed it up. I changed the variable name as you suggested also.
This is the final working code 🙂
var DT = new Date();
var EXP = this.getField("test expiry").value;
var EXD = util.scand("dd-mmm-yyyy", EXP);
if (EXD.valueOf() <= DT.valueOf())
{
event.target.textColor = color.red;
}
else
{
event.target.textColor = color.black;
}
this.calculateNow();
Copy link to clipboard
Copied
You should use this free tool: http://practicalpdf.com/the-practicalpdf-date-library-for-adobe-acrobat/