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

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

Explorer ,
Jun 27, 2019 Jun 27, 2019

Copy link to clipboard

Copied

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

Views

575

Translate

Translate

Report

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);

   

...

Votes

Translate

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

Copy link to clipboard

Copied

What is the date format of those fields?

Votes

Translate

Translate

Report

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
Explorer ,
Jun 27, 2019 Jun 27, 2019

Copy link to clipboard

Copied

All 3 fields are MM/DD/YYYY

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Explorer ,
Jun 27, 2019 Jun 27, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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...

Votes

Translate

Translate

Report

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
Explorer ,
Jun 27, 2019 Jun 27, 2019

Copy link to clipboard

Copied

LATEST

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

V/r,

JT

Votes

Translate

Translate

Report

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