
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
1 Correct answer
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);
Copy link to clipboard
Copied
What is the date format of those fields?

Copy link to clipboard
Copied
All 3 fields are MM/DD/YYYY
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.

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

Copy link to clipboard
Copied
This solution worked flawlessly, thank you for the expert advice. I will add this scenario to my toolkit.
V/r,
JT

