How to Auto-Fill a PDF Text Field When Two Checkboxes Match using JavaScript
Question details
The user needs a method to populate a text field automatically in a PDF form only when two specific checkboxes are selected and match designated export values.

- Product
- PDF Editor / Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Designing dynamic interactive PDF forms that require conditional logic and auto-filling capabilities based on user input.
- Observed behavior
- The text field must dynamically update to show 'Close using CL function' if 'checkbox1' equals 'close' and 'checkbox2' equals 'no balance'. Otherwise, the field should remain empty.
Ensure your PDF editing software supports form JavaScript and verify the exact field names and export values of your checkboxes within the form properties.
Apply a Custom Calculation Script to the Text Field
Use a standard if/else JavaScript statement in the text field's calculation properties to verify the states of the target checkboxes.
Interactive PDF forms can execute JavaScript to perform logical checks. By tying a custom calculation script to the destination text field, the form will evaluate the `valueAsString` property of your checkboxes every time a change is made, automatically triggering the text population.
In your PDF form editor's preparation mode, right-click the destination text field and select 'Properties' from the context menu.
Switch to the 'Calculate' tab in the Properties dialog box and choose the 'Custom calculation script' option.
Click the 'Edit' button and paste the following conditional logic: if (this.getField("checkbox1").valueAsString == "close" && this.getField("checkbox2").valueAsString == "no balance") { event.value = "Close using CL function"; } else { event.value = ""; }
Click 'OK' to save the script, close the properties window, and exit form editing mode to test if the text field correctly reacts to your checkbox selections.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office offers a comprehensive PDF toolkit that lets you seamlessly build interactive forms, insert checkboxes, and manage text fields with ease. It's the perfect solution for digitizing your documentation workflow.
- 1. Open the PDF in WPS Office: Launch WPS Office and open your existing PDF document using the built-in PDF viewer.
- 2. Access the Form Tab: Navigate to the 'Form' tab on the top toolbar to access the suite of interactive form creation tools.
- 3. Insert Form Fields: Click on 'Text Field' or 'Check Box' from the ribbon and click anywhere on the page to place the interactive elements.
- 4. Customize Field Properties: Double-click your newly placed fields to rename them, modify their appearance, and set their default export values.

Frequently Asked Questions
Why isn't my text field updating when the checkboxes are clicked?
This commonly occurs if the field names referenced in the JavaScript do not exactly match the actual names of the checkboxes in the PDF, or if the export values differ. Double-check your spelling, spaces, and capitalization.
How do I find the correct export value of a checkbox?
In form editing mode, right-click the specific checkbox, select 'Properties', navigate to the 'Options' tab, and locate the 'Export Value' box. This is the exact value you must use in your script.
Can I modify the script to work with three or more checkboxes?
Yes, you can append extra conditions using the '&&' (AND) operator. For example: `&& this.getField("checkbox3").valueAsString == "yes"`.
What if I want the text field to populate if EITHER checkbox matches?
To apply 'OR' logic instead of 'AND' logic, replace the `&&` operator in your JavaScript with `||`.




