How to Display -1 or a Blank Field Based on a PDF Checkbox
Question details
The user needs to create a custom calculation script for an interactive PDF form that conditionally displays "-1" in a text field when a specific checkbox is checked, and remains blank when the checkbox is cleared.

- Product
- Adobe Acrobat / PDF Editors
- Device & OS
- not provided
- Scenario
- Setting up advanced conditional logic and auto-calculating fields within an interactive PDF document.
- Observed behavior
- The target text field (e.g., "NO") automatically updates its displayed value dynamically depending on the selected or cleared state of the "Critical" checkbox.
Ensure you are using a PDF editor that fully supports JavaScript calculation scripts (like Adobe Acrobat Pro) and verify the exact export value of your target checkbox in its properties menu.
Add a Custom Calculation Script to the PDF Text Field
Use JavaScript within the target text field's calculation properties to monitor the checkbox state and update the text value dynamically.
Interactive PDF forms allow you to use JavaScript to create dynamic relationships between form fields. By assigning a script to the text field's calculation event, it will automatically listen for changes to the checkbox and update its value accordingly.
Open your PDF document in your advanced PDF editor (e.g., Adobe Acrobat) and select the 'Prepare Form' tool to reveal all editable fields.
Right-click on the text field where you want the '-1' or blank value to appear (e.g., the 'NO' field) and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab in the Properties dialog box and select the 'Custom calculation script' option.
Click the 'Edit' button and paste the following script: var critical = this.getField("Critical"); event.value = critical.valueAsString === "Yes" ? -1 : "";
Click 'OK' to save the script, close the Properties window, and exit form editing mode. Click the 'Critical' checkbox to confirm that the text field updates to -1 when checked and clears when unchecked.

Read, Edit, and Fill PDF Forms Smoothly with WPS Office
While creating advanced JavaScript calculation scripts requires specialized form authoring software, filling out interactive PDFs and managing documents daily is incredibly fast and completely free with WPS Office. It acts as a perfect alternative to heavy, expensive office and PDF software.
- 1. Download and install: Get WPS Office for free from the official website and follow the simple installation instructions.
- 2. Open your PDF form: Launch WPS PDF and open your interactive document to instantly view and interact with editable form fields.
- 3. Fill and save: Click on the checkboxes and text fields to fill out your form seamlessly, then save or export the document directly.

Frequently Asked Questions
Why is my PDF calculation script not updating the field?
This usually happens because the export value in your JavaScript does not match the actual export value of the checkbox. Open the checkbox properties, navigate to the 'Options' tab, and ensure the export value matches the string in your script (e.g., 'Yes', 'On', or 'True').
Can I use a similar script to monitor multiple PDF checkboxes?
Yes, you can expand the custom calculation JavaScript using 'if/else' statements to check the states of multiple checkboxes, allowing the text field to output different numerical values or text strings based on various combinations of selections.
Will these custom PDF scripts work in web browsers?
Not consistently. Many built-in browser PDF viewers and basic mobile PDF readers do not fully support JavaScript for form calculations. It is highly recommended that users fill out these scripted forms using full-featured desktop software like Adobe Acrobat or WPS Office.
How do I hide the text field entirely when the checkbox is cleared?
Instead of setting the field value to blank, you can modify the custom calculation script to change the display property of the field itself. You can add logic like `event.target.display = display.hidden` when the checkbox value evaluates to false or cleared.




