How to Set a PDF Text Field to Zero When Checkbox is Unchecked
Question details
The user needs to configure a PDF form so that a specific text field automatically updates to 0 when an associated checkbox is cleared, and returns to 100 when the checkbox is selected.

- Product
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form where a numerical text field's value dynamically depends on the toggled state of a checkbox.
- Observed behavior
- The text field correctly displays 100 when the checkbox is selected, but fails to revert to 0 when the checkbox is unchecked because the correct condition check is missing.
Ensure you are using a PDF editor that supports form editing and JavaScript execution. Additionally, verify the exact name of your checkbox field under its properties, as script references are strictly case-sensitive.
Apply a Custom Calculation Script to the Text Field
Use a simple JavaScript conditional statement in the text field's calculate properties to check the value of the checkbox.
Because the default value of an unchecked checkbox in PDF forms is "Off", you can use a custom script to test for this specific string. When the value is "Off", the script sets the text field to zero; otherwise, it assigns 100.
Open your PDF in form editing mode. Right-click the text field that you want to display the number, and select 'Properties'.
In the Text Field Properties dialog box, click on the 'Calculate' tab to view calculation options.
Select 'Custom calculation script' and click the 'Edit' button. Enter the following script: event.value = (this.getField("CheckBox36").valueAsString == "Off") ? 0 : 100;
Replace 'CheckBox36' in the script with the exact name of your checkbox. Click 'OK' to save the script.
Close the form editing mode and toggle the checkbox to confirm the text field updates to 0 when unchecked and 100 when checked.

Use a Standard If-Then Conditional Statement
For those who prefer traditional block formatting, a standard if-then statement achieves the exact same result as the inline ternary operator.
Create Interactive PDF Forms with WPS Office
WPS Office offers a robust PDF editor that allows you to seamlessly add interactive form elements like checkboxes and text fields, format your document, and manage PDF data without hassle.
- 1. Open Your PDF Document: Launch WPS Office and open your PDF file using the built-in PDF reader and editor.
- 2. Access Form Editing Tools: Navigate to the 'Form' tab on the top ribbon to access interactive form controls.
- 3. Add Form Elements: Click on 'Text Field' or 'Check Box' and drag on the document to place your form elements.
- 4. Customize Field Properties: Double-click any form field to open the properties panel and configure its appearance, format, and interactions.

Frequently Asked Questions
Why is my PDF calculation script not updating the text field?
This usually happens due to a typo or incorrect casing in the field name. PDF JavaScript is strictly case-sensitive. Ensure that the name specified in this.getField('FieldName') perfectly matches the actual property name of the checkbox.
How do I find the exact name of my PDF checkbox?
Enter form editing mode, right-click the checkbox, and select 'Properties'. Under the 'General' tab, you will see the exact 'Name' of the field. Copy this name to use in your calculation scripts.
What is the default value of an unchecked checkbox in standard PDF forms?
By default, when a checkbox is cleared or unchecked in a standard PDF form, its value is interpreted as the string "Off". That is why checking for "Off" in a calculation script accurately determines if it is unchecked.
Can I hide the text field entirely when the checkbox is unchecked instead of showing zero?
Yes. Instead of changing event.value in a calculation script, you would add a Mouse Up action to the checkbox itself that toggles the text field's display property (e.g., this.getField('TextFieldName').display = display.hidden).




