How to Set a PDF Form Field to the Current Year Plus Another Field
Question details
The user needs to configure a calculated PDF form field that dynamically adds the current calendar year to a numeric value inputted in a different form field.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where a specific field needs to display a future year automatically calculated based on the current year and user input (e.g., current year + 4).
- Observed behavior
- A custom JavaScript calculation is required to retrieve the system's current year and mathematically combine it with another field's string value, rather than relying on standard preset formulas.
Ensure your PDF editing software supports form field creation and custom JavaScript execution, and note the exact name of your input field before starting.
Use a Custom JavaScript Calculation in Field Properties
Apply a short JavaScript snippet to the calculated field's properties to automatically fetch the current year and add it to the designated input field.
PDF forms use standard JavaScript to handle complex calculations. By writing a custom calculation script for your target field, you can pull the current system year using the Date object and add it to the value parsed from your input field.
Open your PDF form in editing mode. Locate the field where users will enter the number (e.g., '4'). Double-click it to check its properties and note the exact 'Name' (for example, 'B').
Create or locate the text field where you want the final calculated result to appear (e.g., field 'A'). Right-click this field and select 'Properties'.
In the Text Field Properties dialog box, click on the 'Calculate' tab at the top.
Select the 'Custom calculation script' radio button, then click the 'Edit...' button. Paste the following code: event.value = new Date().getFullYear() + Number(this.getField("B").valueAsString); (Replace "B" with your actual input field name).
Click 'OK' to close the JavaScript editor, then click 'Close' on the properties window. Switch to preview or hand tool mode, enter a number in the input field, and press Enter to see the result update automatically.

Add Document-Level JavaScript for Auto-Updating on Open
Ensure the calculated year updates immediately if a user opens the file in a new calendar year, without waiting for a field to be edited.
Easily Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to view, fill, and manage complex interactive PDF forms effortlessly without requiring expensive software.
- 1. Install WPS Office: Download and install the free WPS Office suite on your device.
- 2. Open Your PDF Form: Launch WPS PDF and open your interactive PDF document containing the calculated fields.
- 3. Fill and Save Automatically: Enter your data into the form fields. WPS PDF will automatically execute standard embedded JavaScript calculations, allowing you to save the correctly filled form.

Frequently Asked Questions
Why isn't my PDF form calculation updating when I change the number?
Calculated fields typically update when you interact with another field. If it is not updating, ensure that the JavaScript syntax is completely accurate (it is case-sensitive), the field names match exactly, and 'Automatically calculate field values' is enabled in your PDF viewer's Preferences.
Can I subtract a value from the current year instead of adding?
Yes. You can simply change the mathematical operator in the JavaScript code. Replace the '+' sign with a '-' sign: event.value = new Date().getFullYear() - Number(this.getField('B').valueAsString);
Do recipients need Adobe Acrobat to fill out this calculated form?
No. Any standard, modern PDF viewer that supports form JavaScript processing—such as WPS Office PDF or most popular web browsers—will successfully execute the calculation scripts when the recipient fills out the form.




