Fix Acrobat Custom Calculation Script Not Displaying a Result
Question details
A custom JavaScript calculation designed to calculate the number of days between two date fields fails to display any result in the target field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where a specific field is supposed to automatically calculate and display the lead time based on two input dates.
- Observed behavior
- The calculation field remains entirely blank despite the date formats and field names appearing correct. Additionally, clearing one of the date fields might cause the target field to retain an outdated value.
Ensure that you have sufficient permissions to edit the PDF form and that JavaScript is enabled in your PDF viewer's preferences (Edit > Preferences > JavaScript).
Add an 'Else' Condition and Verify Script Placement
Update the calculation script to handle empty date fields properly and ensure it is placed in the exact Custom Calculation Script area.
When writing custom JavaScript for PDF date calculations, the script will often fail to update or display results if one of the referenced fields is empty. By defining an 'else' condition, you force the field to clear itself rather than breaking the script or holding an old value.
It is also critical to confirm that the script is applied directly to the target calculated field, rather than document-level scripts.
Open your PDF in 'Prepare Form' mode, right-click the target calculated lead-time field, and select 'Properties'.
Navigate to the 'Calculate' tab, choose the 'Custom calculation script' radio button, and click the 'Edit' button.
At the very end of your existing calculation code, add the line: `else event.value = "";`.
Click 'OK' to save the script, close the properties window, and test the form by entering and clearing dates in the source fields.

Debug Errors Using the JavaScript Console
Use the built-in JavaScript Debugger to identify syntax or reference errors blocking the calculation.
Effortlessly Manage and Edit PDF Forms with WPS Office
Bypass complex script debugging by using WPS Office's intuitive PDF editing tools. WPS Office provides a streamlined, user-friendly interface to manage interactive form fields, edit PDF text, and handle daily document workflows with ease.
- 1. Install WPS Office: Download and install the free version of WPS Office from the official website.
- 2. Open Your PDF: Launch WPS PDF and open the interactive form you want to edit.
- 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to easily add, modify, or format text fields and checkboxes without writing complex code.

Frequently Asked Questions
Why does my calculated date field show an incorrect format?
The target field needs to know how to display the calculated result. Right-click the field, select 'Properties', go to the 'Format' tab, and ensure the format category is correctly set (e.g., 'Number' for days, or 'Date' if outputting a specific date).
How do I find the exact field name Acrobat generated?
In 'Prepare Form' mode, look at the 'Fields' pane on the right-hand side of your screen. This list displays the exact, actual names of all fields in the document, including any system-added suffixes like '_af_date' that your script must reference exactly.
Why does the calculation not update when I change a field value?
This usually happens due to an incorrect calculation order, especially if multiple fields depend on each other. You can fix this by going to the 'More' option (or the settings menu) in the Prepare Form toolbar and selecting 'Calculate Order' to arrange them logically.




