PDF Editing Issues

How to Show PDF Form Text Fields Based on a Number Entered by the User

Huma Ashraf ChHuma Ashraf Ch Nov 3, 2026 869 views

Question details

The user wants to configure a fillable PDF form to dynamically display a specific number of mandatory text fields corresponding to a numerical value entered by the user (e.g., showing five attendee fields if the user types '5').

How to Show PDF Form Text Fields Based on User Input
Product
PDF Editors
Device & OS
not provided
Scenario
Creating advanced fillable PDF forms for data collection, such as event registrations, where the required number of participant detail fields varies.
Observed behavior
Standard PDF files cannot dynamically generate new fields and reflow the document to make room. Showing fields based on input requires JavaScript and pre-drawn hidden fields, or the use of dynamic XFA forms.
Before you start

Before applying any logic, map out the layout of your PDF page to ensure there is enough blank, fixed physical space to accommodate the maximum number of text fields a user could potentially trigger.

Solution 1Recommended

Use JavaScript to Show or Hide Predefined PDF Fields

Since standard PDF files cannot automatically expand to make room for new fields, the most effective method is to pre-create the maximum number of fields as 'Hidden' and use JavaScript to reveal them.

Standard PDF forms (Acroforms) have a fixed layout and cannot dynamically push existing text down to insert new rows. To achieve the illusion of dynamic fields, you must create all possible text fields in advance.

By applying a custom JavaScript to the numerical input field, you can calculate the entered value and loop through the predefined fields, changing their visibility property and marking them as required based on the user's input.

1
Pre-create the maximum required fields

Open your form in a PDF editor that supports form creation. Draw the maximum number of text fields you expect to need (e.g., Attendee_1, Attendee_2 ... Attendee_10) and set their default visibility property to 'Hidden'.

2
Create the numerical trigger field

Insert a text field designated for the number input (e.g., named 'NumAttendees'). This is where the user will enter their desired number.

3
Add a Custom Keystroke or Validation Script

Right-click the 'NumAttendees' field, navigate to Properties > Format (or Validate), and choose to run a custom JavaScript. Write a loop script that checks the entered value.

4
Configure visibility and mandatory rules

In your script, set the `display` property of the needed fields to `display.visible` and their `required` property to `true`. Ensure the script hides any remaining fields and sets them as not required.

Use JavaScript to Show or Hide Predefined PDF Fields
Document Space Limitations: Because the document will not reflow, you must ensure that your base PDF design has enough white space allocated for all predefined fields to be visible simultaneously without overlapping other text.
Manage PDF Forms Easily

Create and Manage Fillable PDF Forms with WPS PDF

WPS Office offers a comprehensive set of PDF tools to easily design interactive fillable forms. You can quickly add text fields, checkboxes, and buttons, adjusting their properties precisely before finalizing your dynamic document.

  1. 1. Open your PDF in WPS: Launch WPS Office and open your base PDF document using the built-in WPS PDF editor.
  2. 2. Access the Form tools: Navigate to the 'Form' tab on the top ribbon to view the comprehensive suite of interactive field options.
  3. 3. Insert and configure Text Fields: Click the 'Text Field' tool to draw your predefined fields. Double-click any field to access its properties, where you can set its default state to hidden or required.
  4. 4. Save the fillable structure: Once your layout is properly spaced for all potential fields, save the PDF. Your standard form structure is now ready for script integrations or distribution.
Easily draw, align, and customize text fields across your PDF form.Configure field properties such as Read-Only, Hidden, or Mandatory with a few clicks.Highly compatible with standard Adobe PDF form structures and layouts.Free, lightweight, and user-friendly interface for daily PDF editing and form filling.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PDF not expand to make room for newly visible text fields?

Standard PDF forms (Acroforms) have fixed physical layouts. They cannot automatically reflow or push text downwards when new content appears. Elements must be pre-drawn in an empty, fixed space and toggled between hidden and visible states.

How do I make a newly visible PDF field mandatory based on user input?

When using JavaScript to change a specific text field's visibility to visible, you can simultaneously modify its 'required' property. For example, adding `getField('Attendee1').required = true` inside your script ensures the user cannot submit the form without filling it out.

What is the difference between Acroforms and XFA forms in PDF?

Acroforms are standard, fixed-layout PDF forms widely supported by almost all PDF viewers. XFA (XML Forms Architecture) forms allow for truly dynamic, reflowable layouts where fields can be added on the fly. However, XFA forms require specialized enterprise software to create and are not supported by many mobile or third-party PDF readers.

Can I hide the text fields again if the user changes their input to a lower number?

Yes. The JavaScript attached to your numerical input field will run again when the number changes. It will re-evaluate the input, change the extra text fields back to 'hidden', and remove their 'mandatory' requirement so the form behaves correctly.