Copy link to clipboard
Copied
I have a payroll claim form in which I need a warning message to appear if the claim date is more than 62 days prior to the current date. The forums and links have been very useful to get me to a point where my script works in a test form with just 3 fields - the claim date, claim value and warning message. The warning message is in a text field with the property set to hidden by default (and I have a document level script to reset its display property on closing). The issue I have is that the script doesn't seem to work consistently now I have placed it into the working form. Essentially if the claim date is entered that is less than 62 days old then the message remains hidden but it also doesn't then appear if a date is entered that is more than 62 days old. If that old date is then deleted from the field on hitting enter the warning message is revealed. If a further date is entered that is less than 62 days old the message will be hidden again. The script I am running is below. These are my first experiences of javascript in Acrobat so the script may not be that elegant but I would be grateful if you could assess where my issue might be in getting it to react to the date input consistently.
Input date field is labelled c1Date and is formatted as date “dd/mm/yy”
The warning message is in text field named "Warning"
My script is:
var curDate = new Date(); // gets todays date
var msDate = curDate.getTime(); // converts todays date to milliseconds
var c1Date = getField("c1Date").value; // gets the input value of date field
var c1Date2 = util.scand("dd/mm/yy", c1Date); //formats input to date
var msC1 = c1Date2.getTime(); // converts input date to milliseconds
var expireDate = 62*24*60*60*1000; // calculates 62 days as milliseconds
if ((msDate - msC1) > expireDate) // tests if input is 62 days or more old
this.getField("Warning").display = display.visible; // if TRUE make warning visible
else this.getField("Warning").display = display.hidden; // if FALSE leave warning hidden
Thank you
Then replace this line:
var c1Date = getField("c1Date").value;
With this:
var c1Date = event.value;
Copy link to clipboard
Copied
Where did you place this script? Under what event, and of which field?
Copy link to clipboard
Copied
Thank you. The script is in the validate property of the c1Date field.
Copy link to clipboard
Copied
Then replace this line:
var c1Date = getField("c1Date").value;
With this:
var c1Date = event.value;
Copy link to clipboard
Copied
Thank you for your help. I'll try this first thing tomorrow and feedback.
Copy link to clipboard
Copied
Thank you for your help. This works perfectly.
Copy link to clipboard
Copied
Thank you. The script is in the validate property of the c1Date field.