PDF Editing Issues

How to Select Part of a Form Field's Text with Acrobat JavaScript

Bushra ParveenBushra Parveen Nov 10, 2026 869 views

Question details

The user wants to know if it is possible to use Acrobat JavaScript to automatically select a specific substring of text inside a form field when it receives focus.

Can Acrobat JavaScript Select Part of a Form Field's Text?
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Attempting to auto-select generated text, such as a photo number or prefix, inside a single text field when the user clicks into it.
Observed behavior
Acrobat JavaScript does not reliably select an arbitrary substring inside a text field upon receiving focus.
Before you start

Identify which parts of your PDF form data are static and which require user input. Since Acrobat's JavaScript API cannot reliably select substrings within a single text field, redesigning the form layout to separate these elements is the most effective approach.

Solution 1Recommended

Use Separate Text Fields for Generated and Editable Text

The most reliable workaround is to split the generated static text and the user-editable text into two distinct form fields.

Because Acrobat JavaScript cannot isolate part of a text string for selection, breaking the information into two fields ensures predictable editing. The static portion can be locked, while the editable portion remains fully accessible to the user.

1
Delete the original field

Open your PDF form editor, locate the single text field causing the issue, and delete it.

2
Create a read-only field

Insert a new text field for the generated text (e.g., the photo number). Right-click it, go to Properties, and check the 'Read Only' box.

3
Create an editable field

Insert a second text field directly adjacent to the first one. Leave this field editable so the user can input their data independently.

Use Separate Text Fields for Generated and Editable Text
Layout Alignment: You can remove the borders of both fields and place them close together so they visually appear as a single input area to the user.
Easily Manage PDF Forms

Design Interactive PDF Forms with WPS Office

Avoid complex JavaScript workarounds by designing intuitive PDF forms directly in WPS Office. You can easily add, format, and align multiple text fields to create user-friendly and professional documents without relying on advanced scripting.

  1. 1. Open your PDF document: Launch WPS Office and open the PDF file you want to edit.
  2. 2. Access form tools: Navigate to the 'Form' tab located on the top ribbon.
  3. 3. Insert text fields: Click on 'Text Field' to insert new, separate boxes for static and editable text.
  4. 4. Adjust properties: Double-click the newly created fields to adjust their properties, such as setting generated text to read-only.
  5. 5. Save changes: Save your document to finalize the new, user-friendly form layout.
Easily insert and align interactive PDF form fieldsHighly compatible with standard Adobe PDF formatsSet field properties like 'Read Only' with a single clickLightweight application with an intuitive, user-friendly interface
microsoft office alternative - wps office

Frequently Asked Questions

Why can't Acrobat JavaScript select part of a text field?

Acrobat's JavaScript API lacks a native method to highlight or select specific substrings within a single text field when it receives focus. By default, it either selects the entire field's contents or simply places the cursor inside the field.

Can I make only part of a text field read-only in a PDF?

No, a single PDF text field cannot have mixed permissions. To achieve this effect, you must split the field into two separate text fields: one set to 'Read Only' for the static text, and the other left fully editable.

Can JavaScript select the entire text field on focus?

Yes, you can use JavaScript to automatically select the entire contents of a text field when the user clicks into it. However, isolating just a portion of the text (like a prefix or ID number) is not supported.