Skip to main content
martint1968230
Participant
September 13, 2018
解決済み

Change display property of a field on outcome of if then else test

  • September 13, 2018
  • 返信数 2.
  • 670 ビュー

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

このトピックへの返信は締め切られました。
解決に役立った回答 try67

Then replace this line:

var c1Date = getField("c1Date").value;

With this:

var c1Date = event.value;

返信数 2

martint1968230
Participant
September 13, 2018

Thank you. The script is in the validate property of the c1Date field.

try67
Community Expert
Community Expert
September 13, 2018

Where did you place this script? Under what event, and of which field?

martint1968230
Participant
September 13, 2018

Thank you. The script is in the validate property of the c1Date field.

try67
Community Expert
try67Community Expert解決!
Community Expert
September 13, 2018

Then replace this line:

var c1Date = getField("c1Date").value;

With this:

var c1Date = event.value;