Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Show/Hide message based on if a date falls between 2 input dates.

Guest
Jun 27, 2019 Jun 27, 2019

I have a form that has 2 date inputs representing the start and end date of a trip.

I have a 3rd date input that requests the company credit card expiration date.  I want to show/hide a message that says something along the lines of "card will expire during trip" if the expiration date of the credit card is before the end date.

In summary.

Input start date, input end date, input cc expiration date.  If cc expiration date is before end date, show a message, if not, message is hidden.

Thanks in advance.

JT

TOPICS
Acrobat SDK and JavaScript , Windows
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 27, 2019 Jun 27, 2019

You can use this code as the custom calculation script of the field where you want to display this error message:

var startDateString = this.getField("StartDate").valueAsString;

var endDateString = this.getField("EndDate").valueAsString;

var expiryDateString = this.getField("ExpiryDate").valueAsString;

event.value = "";

if (startDateString!="" && endDateString!="" && expiryDateString!="") {

    var d1 = util.scand("mm/dd/yyyy", startDateString);

    var d2 = util.scand("mm/dd/yyyy", endDateString);

   

...
Translate
Community Expert ,
Jun 27, 2019 Jun 27, 2019

What is the date format of those fields?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 27, 2019 Jun 27, 2019

All 3 fields are MM/DD/YYYY

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 27, 2019 Jun 27, 2019

You can use this code as the custom calculation script of the field where you want to display this error message:

var startDateString = this.getField("StartDate").valueAsString;

var endDateString = this.getField("EndDate").valueAsString;

var expiryDateString = this.getField("ExpiryDate").valueAsString;

event.value = "";

if (startDateString!="" && endDateString!="" && expiryDateString!="") {

    var d1 = util.scand("mm/dd/yyyy", startDateString);

    var d2 = util.scand("mm/dd/yyyy", endDateString);

    var d3 = util.scand("mm/dd/yyyy", expiryDateString);

    if (d3.getTime()>=d1.getTime() && d3.getTime()<=d2.getTime()) event.value = "card will expire during trip";

}

Adjust the field names in the first 3 lines of the code to match the actual ones in your file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 27, 2019 Jun 27, 2019

Thank you fo your quick responses!

After thinking about it, does the start date have relevance?  In the end, I just want to know if the expiration date is before the end date right?

JT

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 27, 2019 Jun 27, 2019

I think so, but maybe not in the way you currently have it set up. What if the card expires before they go on the trip?

The code above won't warn them about that situation, but you probably would want it to...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 27, 2019 Jun 27, 2019
LATEST

This solution worked flawlessly, thank you for the expert advice.  I will add this scenario to my toolkit.

V/r,

JT

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines