How to Hide an Empty Fillable PDF Form Field Using JavaScript
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.

- 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.
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.
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.
Launch your form editing software and select the multiline form field that needs to be conditionally hidden.
Open the Script Editor palette and select an appropriate event trigger from the 'Show' dropdown, such as the 'calculate' or 'validate' event.
Enter a JavaScript condition to check if the field is empty: if (this.rawValue == null || this.rawValue == '') { this.presence = 'hidden'; } else { this.presence = 'visible'; }
Switch to the PDF Preview tab, leave the field blank, and verify that the field area disappears to reveal the background lines.

Modify the Display Property for Standard AcroForms
Use this method if your PDF is a standard AcroForm created in Acrobat or a standard PDF editor.
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. Open WPS Office: Launch WPS Office on your computer and click on the 'PDF' tool from the main dashboard.
- 2. Load your PDF Form: Click 'Open' and select your interactive PDF form document to load it into the WPS PDF viewer.
- 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. 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. 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.

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.




