PDF Editing Issues

Use JavaScript in Adobe Acrobat to Populate a Form Field From a Date

Kushani NimanthikaKushani Nimanthika Nov 18, 2026 869 views

Question details

Populate a PDF form field with the holiday or company event associated with a selected date.

Populate an Adobe Acrobat Form Field Based on a Selected Date
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form uses JavaScript to look up an event based on the value of a date field.
Observed behavior
Only the final event appears because successive assignments overwrite earlier results.
Before you start

Open the PDF in Adobe Acrobat and check the exact names of the date field and the field that will display the event. Confirm the date field's displayed format, since the script compares its text exactly.

Solution 1Recommended

Use an if-else chain in the event field's calculation script

Use this method to assign one event for each matching date and clear the field when no date matches.

In a custom calculation script, event.value is the value assigned to the field being calculated. An if-else chain prevents later assignments from overwriting a match.

1
Open the event field properties

In Acrobat, open the PDF and select Prepare a form. Open Properties for the field that should display the holiday or company event.

2
Edit the calculation script

On the Calculate tab, select Custom calculation script and click Edit. Replace the existing assignments with: var d = this.getField("Date").valueAsString; if (d == "January 17, 2022") event.value = "Martin Luther King Day"; else if (d == "February 21, 2022") event.value = "Presidents Day"; else if (d == "June 22, 2022") event.value = "Company Picnic"; else event.value = "";

3
Match your field and date format

In the script editor, replace "Date" with the exact name of your date field. Change the date strings and event names to match your form, using the same format shown in the date field.

4
Test the form

Save the script and close the field properties. Use Preview in Prepare a form to select each date and confirm that the event field updates; also test an unmatched date to confirm the field clears.

Use an if-else chain in the event field's calculation script
Exact date matches: The sample dates are from 2022. Update them for your schedule, and make sure each string matches the date field's displayed value exactly.
Free Microsoft Office alternative

Work With Office Documents and PDFs in WPS Office

WPS Office is a free, lightweight alternative for working with documents, spreadsheets, presentations, and PDFs. Its familiar interface and Microsoft Office format support make it easier to move existing files into a single workspace. Use Adobe Acrobat for the form's JavaScript calculation; WPS is not a fix for that Acrobat script.

Open and review PDF documents alongside your office filesCompatible with Microsoft Office formats including DOCX, XLSX, and PPTXFamiliar editing interface for a smooth transition from Microsoft OfficeFree, lightweight tools for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PDF form show only the last event?

If the script assigns event.value repeatedly, each assignment can replace the previous result. Put the date checks in an if-else chain so only the matching branch assigns the event.

Where should I add the JavaScript in Acrobat?

Open Prepare a form, open Properties for the field that will display the event, and select Calculate > Custom calculation script > Edit. The script assigns the result to that field through event.value.

Why is the event field blank when I select a date?

Check that this.getField("Date") uses the date field's exact name and that the date string in the script matches the field's displayed format. The final else branch clears the event field when no string matches.

Can I use a switch statement instead of if-else?

Yes. Read the date with this.getField("Date").valueAsString, use a switch case for each exact date string, assign event.value in each case, and add a break after each assignment. Use a default case to clear unmatched dates.