PDF Editing Issues

How to Hide an Empty Fillable PDF Form Field Using JavaScript

Chanuka GeekiyanageChanuka Geekiyanage Nov 2, 2026 869 views

Question details

The user wants a multiline fillable PDF form field to disappear when it is empty so that the printed lines underneath remain visible for handwritten entries.

How to Hide an Empty Fillable PDF Form Field Using JavaScript
Product
PDF Form Editors
Device & OS
not provided
Scenario
Modifying an interactive PDF form to support both digital entry and physical printing with handwritten lines.
Observed behavior
The attempted JavaScript using the rawValue and presence properties is not working as expected.
Before you start

Determine whether your PDF form is an Adobe LiveCycle form (XFA) or a standard AcroForm, as the JavaScript scripting models and properties for hiding fields differ significantly between the two.

Solution 1Recommended

Use the Presence Property for LiveCycle Forms (XFA)

Apply this solution if your form was created using Adobe LiveCycle Designer, which relies on XML-based dynamic properties.

In LiveCycle forms, field visibility is controlled by the 'presence' property. You must attach the script to an appropriate event (like 'calculate' or 'exit') to dynamically check if the field has been filled.

1
Open the form in LiveCycle Designer

Launch your form editing software and select the multiline form field that needs to be conditionally hidden.

2
Access the Script Editor

Open the Script Editor palette and select an appropriate event trigger from the 'Show' dropdown, such as the 'calculate' or 'validate' event.

3
Write the evaluation script

Enter a JavaScript condition to check if the field is empty: if (this.rawValue == null || this.rawValue == '') { this.presence = 'hidden'; } else { this.presence = 'visible'; }

4
Test the form

Switch to the PDF Preview tab, leave the field blank, and verify that the field area disappears to reveal the background lines.

Use the Presence Property for LiveCycle Forms (XFA)
Script Language Setting: Make sure your Script Editor language is set to 'JavaScript' rather than 'FormCalc' before pasting the code.
Manage and Edit PDF Forms Seamlessly

Create and Fill PDF Forms with WPS PDF

WPS Office offers robust PDF tools to create, edit, and manage fillable forms. While advanced dynamic JavaScript requires specific Adobe environments, WPS PDF provides an intuitive interface for everyday form building, data entry, and seamless document printing without complex coding.

  1. 1. Open WPS Office: Launch WPS Office on your computer and click on the 'PDF' tool from the main dashboard.
  2. 2. Load your PDF Form: Click 'Open' and select your interactive PDF form document to load it into the WPS PDF viewer.
  3. 3. Fill the form fields: Simply click on the highlighted fillable fields to input your data, select checkboxes, or choose items from dropdown menus.
  4. 4. Edit form layout (Optional): Navigate to the 'Form' tab on the top ribbon if you need to add new text fields, check boxes, or push buttons to your document.
  5. 5. Save or Print: Once filled, click the 'Save' icon to keep a digital copy, or go to Menu > Print to generate a physical copy with your entries.
Easily fill, save, and print interactive PDF forms with high reliability.Fully compatible with standard Adobe Acrobat PDF forms (AcroForms).Insert text, images, and electronic signatures directly into any PDF.Lightweight software with a user-friendly, familiar interface.
QA img-9

Frequently Asked Questions

Why isn't my JavaScript working on my PDF form?

Your script might fail if you are applying LiveCycle (XFA) syntax to a standard AcroForm, or vice versa. Ensure you use the 'presence' property exclusively for LiveCycle forms and the 'display' property for standard AcroForms.

How do I make a PDF form field visible only on screen but hidden when printed?

In standard AcroForms, you can open the field Properties, navigate to the 'General' tab, and set the 'Form Field' property dropdown to 'Visible but doesn't print'. This avoids the need for JavaScript.

What is the difference between a LiveCycle form and an AcroForm?

AcroForms are the traditional standard for PDF forms and are broadly compatible with most PDF viewing software. LiveCycle (XFA) forms are dynamic, XML-based forms that can automatically adjust layout and paging, but they require specific Adobe software to render and execute scripts properly.