How to Automatically Set a PDF Form Field Based on an Amount
Question details
The user needs to configure a PDF form so that a specific field automatically updates its text value depending on the numeric value entered into an amount field.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Setting up dynamic PDF form fields where the 'Finance Officer' field automatically displays 'Not Applicable' for amounts under $1,000 or a specific name for amounts over $1,000.
- Observed behavior
- The user wants a conditional setup to output fixed text depending on a mathematical threshold evaluated from a user-input currency amount.
Ensure you are using a PDF editor that supports form creation and custom JavaScript calculations, and confirm the exact name of the amount field in your document before proceeding.
Add a Custom JavaScript Calculation to the Form Field
Use a custom calculation script within the target field's properties to evaluate the amount entered and automatically assign the appropriate text value.
By utilizing standard PDF JavaScript functionality, you can extract the value from your 'Amount' field, strip away any currency symbols or commas, and use a conditional if/else statement to populate the 'Finance Officer' field automatically.
Enter PDF form editing mode. Right-click on the target 'Finance Officer' text field and select 'Properties' from the context menu.
In the Text Field Properties dialog box, click on the 'Calculate' tab at the top.
Choose the option labeled 'Custom calculation script' and click the 'Edit' button to open the JavaScript editor.
Paste the following script: var amount = Number(this.getField('Amount').valueAsString.replace(/[$,]/g, '')); if (amount <= 1000) { event.value = 'Not Applicable'; } else { event.value = 'Jane Doe'; }. Replace 'Amount' and 'Jane Doe' with your exact field name and desired officer name.
Click 'OK' to close the editor, then 'Close' the properties window. Switch to the form filling view and type a number into the Amount field to test the automated result.

Easily Handle and Fill PDF Forms with WPS Office
WPS Office offers a comprehensive and user-friendly PDF toolkit. Whether you need to fill out interactive forms with automated fields, sign documents securely, or edit existing PDF text, WPS Office makes document management fast and seamless.
- 1. Open WPS Office: Launch the WPS Office application and navigate to the PDF tab.
- 2. Load Your PDF Form: Click 'Open' to load your interactive PDF form document into the viewer.
- 3. Fill the Form Fields: Click directly into the text fields to enter your data. Calculated fields will automatically update as you type.
- 4. Save or Export: Once completed, click 'Save' or export your filled PDF form to share it securely.

Frequently Asked Questions
Why is my PDF form calculation script not returning any value?
This usually happens if the field name specified in your `this.getField("FieldName")` script does not exactly match the actual field name in the PDF. Check for typos, extra spaces, and ensure capitalization matches perfectly.
How do I make the field editable if the amount is over $1,000?
If the officer's name changes frequently and needs to be typed manually, do not use `event.value = "Jane Doe";`. Instead, you can set `event.value = "";` in the else block and ensure the field is not locked, allowing the user to click into it and type a name manually.
Why is the script failing when a user types a dollar sign ($)?
JavaScript cannot perform math directly on strings containing currency symbols. Ensure your script includes `.replace(/[$,]/g, "")` to strip out dollar signs and commas before evaluating the number, as shown in the recommended solution.
Do custom PDF JavaScript calculations work on mobile devices?
While desktop PDF applications fully support custom calculation scripts, many mobile PDF readers have limited or no support for JavaScript. It is highly recommended to fill out complex, script-heavy PDF forms on a desktop computer for full functionality.




