Need to validate second date

New Here ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Hello,

 

I am creating a fillable PDF form using Adobe Acrobat DC. There are two fields that requires the person to select dates - Start and End date. How can we have the End date check to make sure that it is AFTER the Start date? Please see attachment for screen capture.

TOPICS
Create PDFs, JavaScript, PDF forms

Views

86

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 , Mar 22, 2021 Mar 22, 2021
You will have to write a custom validation script for the end date field. Something like this shoud work (not tested, so there might be errors): var retVal = true; // get information from "Date1" var d1 = this.getField("Date1_af_date").value; if (d1 == "") { app.alert("Start date is empty"); retVal = false; } if (retVal && event.value == "") { app.alert("End date is empty"); retVal = false; } if (retVal) { var d1 = new Date(d1); var d2 = new Date(event.value); if (d...

Likes

Translate

Translate
Adobe Community Professional ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

You will have to write a custom validation script for the end date field. Something like this shoud work (not tested, so there might be errors):

 

var retVal = true;
// get information from "Date1"
var d1 = this.getField("Date1_af_date").value;
if (d1 == "") {
    app.alert("Start date is empty");
    retVal = false;
}
if (retVal && event.value == "") {
    app.alert("End date is empty");
    retVal = false;
}
if (retVal) {
    var d1 = new Date(d1);
    var d2 = new Date(event.value);
    if (d1 > d2) {
        app.alert("End date needs to be after start date");
        retVal = false;
    }
}
event.rc = retVal;

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
New Here ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

LATEST

Thanks Karl! It works!

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