How to Use Acrobat JavaScript to Set PDF Form Values Based on Input
Question details
The user needs to dynamically calculate a household size from specific input fields and auto-populate a target field with a conditional value based on that size using JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms that require conditional logic to automatically display numerical values or text based on a user's prior input.
- Observed behavior
- The target field remains static or empty until a custom JavaScript calculation is applied with if/else conditions to populate the correct conditional value.
Ensure that all text fields (such as 'FamilySize' and the target output field) are already created in your PDF form and note their exact field names for the script.
Apply a Custom Calculation Script with If/Else Logic
Use a custom JavaScript calculation script on the target form field to evaluate the input values and set the corresponding result.
JavaScript is highly effective for automating form calculations. By accessing the value of the reference field (e.g., FamilySize) and applying conditional if/else statements, the PDF can dynamically update the target field (e.g., PovGuideline).
Open your PDF in Acrobat or your preferred advanced PDF editor, and navigate to 'Prepare Form' or 'Form Edit' mode to view all interactive fields.
Right-click the target field (e.g., 'PovGuideline') where you want the result to appear, select 'Properties', and go to the 'Calculate' tab.
Choose the 'Custom calculation script' option and click the 'Edit' button to open the JavaScript text editor window.
Type your conditional logic. For example: var f = this.getField("FamilySize").valueAsString; if (f === "2") event.value = "$17,240"; else if (f === "3") event.value = "$18,240"; else if (f === "4") event.value = "$19,240"; else if (f === "") event.value = "";
Click 'OK' to save the script, close the properties window, and preview the document to ensure the field updates automatically when the 'FamilySize' value changes.

Read and Fill Interactive PDF Forms with WPS Office
WPS Office features a robust built-in PDF reader and editor that lets you easily fill out interactive forms, run embedded calculations natively, and manage document workflows without requiring expensive specialized software.
- 1. Open WPS PDF: Launch WPS Office, click on the 'PDF' tab, and open your interactive PDF form document.
- 2. Interact with Form Fields: Click on the interactive fields (text boxes, drop-downs, checkboxes) to input your data. Embedded calculations will run automatically as you type.
- 3. Edit or Add Signatures: Use the 'Fill & Sign' toolbar to insert custom text, stamps, or personal signatures if your document requires authorization.
- 4. Save and Export: Click 'Save' or 'Export to PDF' to lock in your filled data and keep a finalized copy of your document.

Frequently Asked Questions
Why isn't my JavaScript calculation updating the PDF field?
This usually happens if the field names in your script do not exactly match the actual form field names (remember, they are case-sensitive), or if the calculation order in your PDF form is set incorrectly.
How do I calculate a value based on multiple fields?
You can fetch multiple fields in your script (e.g., var a = this.getField('Adults').value; var c = this.getField('Children').value;) and combine them (e.g., var total = a + c;) before assigning the result to event.value.
Can I use standard mathematical operators in PDF JavaScript?
Yes, standard JavaScript mathematical operators like +, -, *, and / can be used to calculate numerical values after securely fetching them using the getField() method.
Does WPS Office support complex JavaScript calculations in PDFs?
WPS PDF supports filling standard interactive forms and automatically running their embedded calculations. However, to write or alter complex custom JavaScript scripts on the backend, specialized PDF form-creation software is typically required.




