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

136

Likes

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

Adobe Community Professional , 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);    ...

Likes

Translate

Translate
Adobe Community Professional ,
Jun 27, 2019 Jun 27, 2019

Copy link to clipboard

Copied

What is the date format of those fields?

Likes

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

Likes

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
Adobe Community Professional ,
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.

Likes

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

Likes

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
Adobe Community Professional ,
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...

Likes

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

Likes

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