PDF Editing Issues

How to Hide PDF Text Fields When Source Fields Are Empty

Anum MushtaqAnum Mushtaq Nov 2, 2026 870 views

Question details

The user wants to prevent a calculated PDF address field from displaying unwanted punctuation when the source fields are empty.

How to Hide PDF Text Fields When Source Fields Are Empty
Product
PDF Editor
Device & OS
not provided
Scenario
Creating or editing a dynamic PDF form with calculated address fields that concatenate multiple source fields.
Observed behavior
The calculated field displays lingering static punctuation (e.g., ", CA,") even when the primary source data fields are completely empty.
Before you start

Ensure you have access to a PDF editor that supports JavaScript form calculations and identify the exact field names (e.g., 'Case City', 'Case State') you wish to use as source data.

Solution 1Recommended

Use JavaScript to Conditionally Format or Hide the Field

Add a custom calculation script to check if the source fields are empty before displaying the concatenated address to avoid leftover punctuation.

By using a simple JavaScript snippet, you can instruct the PDF form to return an empty string or completely hide the field if the primary source field is blank. This prevents stray punctuation from appearing on the final document.

1
Open PDF form properties

Open your PDF form in edit mode, right-click the calculated address field, select 'Properties', and navigate to the 'Calculate' tab.

2
Select custom script

Choose the 'Custom calculation script' option and click the 'Edit' button to open the JavaScript editor.

3
Enter the conditional script

Assign variables to your fields and add an if-statement. For example: var city = this.getField('Case City').valueAsString; var state = this.getField('Case State').valueAsString; var zip = this.getField('Case Zip Code').valueAsString; if (city == '') { event.value = ''; } else { event.value = city + ', ' + state + ' ' + zip; }

4
Alternative: Hide the field

If you want the field hidden rather than just blank, you can use the display property. Add logic to set this.getField('Your Field Name').display = display.hidden when the city is empty, and display.visible when it has a value.

5
Save and test

Click 'OK' to save the script, close the properties window, and test your form by leaving the source fields blank to ensure no punctuation is displayed.

Use JavaScript to Conditionally Format or Hide the Field
Case Sensitivity: Make sure the field names in your script exactly match the names of the fields in your PDF form, as JavaScript is fully case-sensitive.
Powerful PDF Form Editor

Edit and Manage Interactive PDF Forms Easily with WPS Office

WPS Office provides a comprehensive PDF toolkit that allows you to view, fill, edit, and manage interactive PDF forms effortlessly without needing complex configurations.

  1. 1. Download the software: Download and install WPS Office from the official website.
  2. 2. Open your PDF: Launch WPS Office and open your interactive PDF document using the WPS PDF tool.
  3. 3. Access form tools: Navigate to the 'Form' tab in the top ribbon to access various form controls, interactive fields, and properties.
  4. 4. Edit or fill: Edit the form layout or seamlessly fill in the required fields with accurate formatting and display rules.
Easily fill and manage interactive PDF formsHigh compatibility with standard PDF format forms and scriptsLightweight application with an intuitive user interfaceAll-in-one suite combining Writer, Spreadsheet, Presentation, and PDF
microsoft office alternative - wps office

Frequently Asked Questions

Why does my calculated PDF field show commas when it is empty?

When you use a basic concatenation method to combine fields, the static text (like commas or spaces) is included by default. Without conditional logic telling the field to hide those characters when the data is missing, the punctuation will always display.

Can I completely hide the field instead of just making it blank?

Yes, you can use JavaScript to change the field's display property. Setting a field to display.hidden will completely remove it from view and prevent it from printing, while display.visible restores it when data is entered.

Are JavaScript calculation scripts case-sensitive in PDF forms?

Yes, JavaScript is entirely case-sensitive. You must ensure that the field names referenced in your script (e.g., this.getField('Case City')) match your actual form fields exactly, including capitalization and spaces.