How to Use Acrobat JavaScript for Conditional Form Field Values
Question details
The user needs to automatically populate a text field with specific values based on the option selected in a separate drop-down field within a PDF form.

- Product
- Adobe Acrobat / PDF
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where field outputs dynamically change, such as displaying different salary ranges depending on a selected salary grade.
- Observed behavior
- The goal is successfully implemented by applying a custom calculation JavaScript to the output field, evaluating the target drop-down field's value.
Ensure you are using a PDF editor that supports form field properties and custom calculation scripts, and confirm the exact name of your drop-down field before writing the script.
Add a Custom Calculation Script to the Output Field
Use this method to apply a JavaScript snippet that listens to the drop-down field and dynamically updates the output field's value based on logical conditions.
By utilizing custom JavaScript in PDF forms, you can create dynamic documents that respond instantly to user input. This script uses simple if/else logic to check the drop-down selection and assign the corresponding string to the current field.
Open your PDF file and enter the form preparation or editing mode within your PDF software.
Right-click the output text field (where you want the conditional values to appear) and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Calculate' tab to view calculation options.
Select 'Custom calculation script' and click the 'Edit' button. Paste the following code, modifying the field name and values as needed: var grade = this.getField("SalaryGrade").valueAsString; if (grade == "1") event.value = "$50,400/$59,800/$69,200"; else if (grade == "2") event.value = "$55,400/$65,800/$76,200"; else event.value = "";
Click 'OK' to save the script, close the Properties dialog, and test the form by changing the drop-down selection to ensure the text field updates correctly.

Edit and Fill PDF Forms Seamlessly in WPS PDF
While custom JavaScript provides advanced functionality for interactive documents, you can efficiently create, edit, and fill standard PDF forms using WPS Office. It provides an intuitive interface for all your document needs without a steep learning curve.
- 1. Open your PDF in WPS Office: Launch WPS Office and open the PDF document you want to edit or fill out.
- 2. Access form tools: Navigate to the 'Form' tab on the top ribbon to access interactive form creation tools.
- 3. Edit form fields: Click on existing fields to input your data or use the toolbar options to add new interactive elements to the document.
- 4. Save and share: Once your form is complete, save the PDF and share it instantly for data collection or review.

Frequently Asked Questions
Why isn't my PDF JavaScript calculating automatically?
If the field doesn't update, verify that JavaScript is enabled in your PDF reader's preferences. Additionally, check the 'Field Calculation Order' in your form settings to ensure the drop-down field is processed before the output field.
Can I add more than two conditions in my Acrobat JavaScript?
Yes, you can extend the script by chaining additional 'else if' statements. For example, add 'else if (grade == "3") event.value = "$60,000";' before the final 'else' statement to handle a third drop-down option.
How do I find the exact name of my drop-down field?
While in form editing mode, right-click the drop-down field and select 'Properties'. The exact field name will be listed under the 'General' tab.
Will this JavaScript work when viewing the PDF on a mobile device?
Support for PDF JavaScript varies greatly across mobile applications. While advanced readers like Acrobat Reader for mobile may execute the script, basic built-in viewers (like iOS Preview) typically do not support custom calculations.




