How to Show a Text Field Value Only When a Checkbox is Selected in PDF Forms
Question details
The user wants to configure a PDF text field to display a specific numerical amount only when an associated checkbox is selected, and remain blank otherwise.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where field values depend on checkbox states for conditional calculations.
- Observed behavior
- The text field needs to output a specific value (e.g., 15) when the checkbox is checked, remain empty when unchecked, and remain available for further form calculations.
Ensure your PDF editing software supports JavaScript for custom field calculations and that you have full form editing permissions for the document.
Apply a Custom Calculation Script to the Text Field
Use a simple JavaScript condition within the text field's properties to check whether the target checkbox is toggled on or off.
By default, standard calculation options in PDF forms sum up values, but they don't handle conditional display logic. Adding a brief JavaScript statement forces the text field to evaluate the checkbox's state before outputting a number or remaining blank.
Open your PDF file and enter the form editing or preparation mode provided by your PDF editor.
Right-click the text field where you want the value ($15.00) to appear and select 'Properties' from the context menu.
In the Text Field Properties dialog box, click on the 'Calculate' tab to view the calculation options.
Select the 'Custom calculation script' option and click the 'Edit' button. Paste the following script: event.value = this.getField("Checkbox1").valueAsString == "Off" ? "" : 15; (replace "Checkbox1" with the exact name of your checkbox).
Click 'OK' to save the script, then close the properties window. Switch to Preview or Hand tool mode to test checking and unchecking the box.

Easily Create and Manage PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor equipped with advanced form-building tools. You can effortlessly insert checkboxes, text fields, and apply properties to create professional, interactive forms.
- 1. Open PDF in WPS Office: Launch WPS Office and open your target PDF document.
- 2. Access Form Tools: Navigate to the 'Form' tab in the top ribbon to view all available form creation tools.
- 3. Insert Form Fields: Click on 'Check Box' or 'Text Field' and draw the field on your document page.
- 4. Adjust Properties: Double-click the newly inserted field to open the Properties panel, where you can customize its name, appearance, and calculation settings.

Frequently Asked Questions
Why does my text field display a 0 instead of remaining blank?
This usually occurs if you are using a standard mathematical function (like 'Value is the sum of') instead of a custom script. Standard calculations default to 0 for empty values. Ensure you are using the custom JavaScript logic that explicitly sets the value to an empty string ("") when the checkbox is 'Off'.
How do I find the exact name of my checkbox to use in the script?
While in the form editing mode, the field name is typically displayed directly over the field placeholder. You can also right-click the checkbox, select 'Properties', and check the 'Name' text box under the General tab.
Can I format the resulting number as currency?
Yes. After adding your custom calculation script, go to the 'Format' tab in the Text Field Properties, select 'Number' from the category dropdown, choose your desired decimal places, and set the currency symbol (e.g., $). The value 15 will then automatically display as $15.00.




