How to Return an Empty String for an Unchecked PDF Checkbox
Question details
The user wants a PDF form calculation script to return an empty string or a specific numeric value when a checkbox is unchecked, bypassing the default 'Off' value.

- Product
- Adobe Acrobat / PDF Editors
- Device & OS
- not provided
- Scenario
- Creating or modifying custom JavaScript calculations for interactive PDF form checkboxes.
- Observed behavior
- When a PDF form checkbox is unchecked, the script evaluates its state as the string 'Off', which interferes with mathematical additions and formatting.
Ensure you have access to the form editing tools and JavaScript properties within your PDF editor. Familiarity with basic JavaScript syntax is recommended before modifying custom form calculations.
Use JavaScript to Explicitly Test for the 'Off' Value
Modify your custom calculation script to explicitly check if the export value is 'Off' and replace it with an empty string or your required numeric value.
By default, standard PDF forms assign the literal string value 'Off' to unchecked checkboxes. To prevent this string from displaying or breaking calculations, you must intercept the value and conditionally return an empty space or a number.
Open your PDF document in Form Editing mode. Right-click the target calculation text field (where you want the result to appear) and select 'Properties'.
Navigate to the 'Calculate' tab inside the Properties window. Select the 'Custom calculation script' option and click 'Edit' to open the JavaScript editor.
Enter the following script to test the checkbox state: var check = this.getField('Check Box4').valueAsString; event.value = (check == 'Off') ? '' : 2; This assigns an empty string if unchecked, or the number 2 if checked.
Click 'OK' to save the script, then 'Close' the properties dialog. Exit Form Editing mode and toggle your checkbox to verify it returns an empty string instead of 'Off'.

Calculate Totals for Multiple Checkboxes
When adding multiple checkbox values together, convert the unchecked 'Off' strings into numeric zeros so mathematical addition works correctly.
Create and Edit Interactive PDF Forms Seamlessly with WPS Office
WPS PDF provides powerful form building and editing tools, enabling you to insert checkboxes, customize export values, and manage PDF documents effectively without advanced coding.
- 1. Open PDF in WPS Office: Launch WPS Office and open your PDF document. Navigate to the 'Form' tab located in the top ribbon.
- 2. Insert Form Controls: Click on 'Check Box' or 'Text Field' from the toolbar to place interactive elements anywhere on your document.
- 3. Customize Field Properties: Double-click the inserted form field to adjust its properties, name, and export values, ensuring the form behaves exactly as you need.

Frequently Asked Questions
Why does my PDF form checkbox return 'Off'?
By default, the PDF specification assigns the hardcoded string value 'Off' to any checkbox or radio button that is not selected. This standard behavior ensures the PDF reader knows the precise toggle state of the element.
Can I change the default 'Off' value in the PDF checkbox properties?
No, the 'Off' state is an inherent part of standard PDF form behavior. While you can change the custom export value for the 'checked' state, you must use a custom JavaScript calculation to alter the output of the 'unchecked' state.
How do I test if a PDF checkbox is checked using JavaScript?
You can test its state by evaluating its value as a string. For example, using `if (this.getField('MyCheckBox').valueAsString != 'Off')` verifies that the checkbox is currently checked and actively using its assigned export value.




