How to Update Multiple PDF Form Fields When a Checkbox is Selected
Question details
The user needs to assign specific numerical values to multiple text fields in a PDF form automatically when a specific checkbox is selected.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where checking a box calculates or auto-fills related text fields.
- Observed behavior
- The user is attempting to use a JavaScript calculation script but needs the correct syntax to retrieve the checkbox state and update the target text fields without generating console errors.
Ensure you have access to a PDF editor with form creation and custom JavaScript calculation capabilities, and verify the exact names of your checkbox and text fields.
Use Custom Calculation JavaScript
Retrieve the checkbox state as a string and assign values to the target text fields using a conditional if/else statement.
To update multiple fields simultaneously when a checkbox is toggled, you need to use a custom calculation script within your PDF form.
It is crucial to retrieve the text field objects themselves rather than just their current values, and assign the new numbers directly to their value property.
Use the code `var checked = this.getField('chk_epoxy').valueAsString;` to get the current state of the checkbox as a string.
Retrieve the target text field objects using `this.getField('FieldName')`. For example, create variables for your text fields like `var comp1 = this.getField('Comp1_epoxy');`.
Write an `if` statement to check if the checkbox value equals 'Yes'. Inside the block, set the `.value` property of each text field to the desired numerical amount.
Add an `else` block to set the text field values back to 0 when the checkbox is unchecked. Make sure you use a lowercase 'else' to prevent syntax errors.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides powerful PDF editing tools that allow you to fill, edit, and manage interactive PDF forms effortlessly without relying on complex external software.
- 1. Open WPS Office: Launch WPS Office and open your PDF document containing the form fields.
- 2. Access Form Tools: Navigate to the Form tab on the top ribbon to view and manage your interactive fields.
- 3. Edit Form Properties: Double-click on the specific form field to adjust its properties, appearance, and calculation settings.
- 4. Save Changes: Once your form fields are configured correctly, save the PDF document to apply the changes.

Frequently Asked Questions
Why is my PDF JavaScript returning a syntax error on the 'else' statement?
JavaScript is strictly case-sensitive. Ensure that you are using a lowercase 'else'. Using 'Else' with a capital 'E' will result in a syntax error in your PDF console.
How do I correctly retrieve a checkbox value in PDF scripting?
You should use the `valueAsString` property. For example, `this.getField('checkboxName').valueAsString` ensures you get the exact string value (like 'Yes' or 'Off') so you can accurately evaluate it in your logic.
Where should I place the custom calculation script in a PDF form?
The script is typically placed in the calculation properties of a text field. If you are updating multiple text fields simultaneously, you can place this script in a hidden text field dedicated solely to performing calculations.




