PDF Editing Issues

How to Use Acrobat JavaScript to Insert an Empty Form Row in PDF

John WilsonJohn Wilson Nov 10, 2026 869 views

Question details

The user needs to insert an empty form row into a PDF form by clicking a button, which requires shifting existing rows downward and clearing the selected row using Acrobat JavaScript.

How to Insert an Empty Form Row Using Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating or modifying interactive PDF forms where users need to dynamically add empty rows for data entry without overwriting existing data.
Observed behavior
Script issues such as incorrect field names, variable scopes, or loop boundaries often cause values to be copied incorrectly or rows to shift unexpectedly.
Before you start

Ensure you have a backup of your original PDF form before editing its JavaScript. Familiarize yourself with the exact naming conventions used for your form fields, as the script relies heavily on accurate and sequential field names.

Solution 1Recommended

Write and Apply JavaScript to Shift and Clear Rows

Use a custom JavaScript triggered by a button click to loop through form rows, shift values downward, and clear the target row.

The logic involves determining the current row where the button was clicked, looping backward from the last row of the form to copy each field's value to the next row, and finally clearing the fields in the selected row to make it empty.

1
Access Button Properties

In your PDF editor, enter form editing mode, right-click the button intended to add a row, and select 'Properties'.

2
Add JavaScript Action

Navigate to the 'Actions' tab, select 'Mouse Up' as the trigger, choose 'Run a JavaScript' from the action dropdown menu, and click 'Add'.

3
Write the Loop Logic

Enter your JavaScript code. Ensure your loop iterates backward (e.g., starting from the final row down to the current row) to prevent overwriting data. Copy the value of each field into the corresponding field of the next row.

4
Clear the Target Row

After the loop finishes shifting the data downward, add code to reset or clear the values of the fields in the row immediately below the insertion point, effectively creating an empty row.

5
Test the Form

Click 'OK' to save the script, exit form editing mode, and click the button to verify that the rows shift downward and an empty row appears correctly.

Write and Apply JavaScript to Shift and Clear Rows
Field Naming Accuracy: Check that your fields are named sequentially (e.g., Row1_Field, Row2_Field) so the JavaScript loop can iterate through them dynamically using string concatenation.
Edit PDF Forms Easily with WPS Office

Use WPS PDF to Manage and Edit Interactive PDF Forms

WPS Office includes a powerful PDF editor that allows you to fill, edit, and manage interactive PDF forms seamlessly. It provides an intuitive interface for handling form fields, text, and data without needing complex programming skills.

  1. 1. Open WPS Office: Launch WPS Office on your computer and click on the 'PDF' tab to open the WPS PDF editor.
  2. 2. Load Your PDF Form: Click 'Open' and select the interactive PDF form you want to edit or fill out from your local files.
  3. 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access various form field tools, including text fields, checkboxes, and interactive buttons.
  4. 4. Edit and Save: Make the necessary adjustments to your form fields or fill in the required data, then click 'Save' to preserve your changes securely.
Comprehensive PDF form filling and editing toolsHighly compatible with standard PDF formats and Adobe Acrobat filesLightweight and fast performance for large PDF documentsBuilt-in tools for converting PDFs to Word, Excel, and PowerPoint
microsoft office alternative - wps office

Frequently Asked Questions

Why are my PDF form values copying incorrectly when the button is clicked?

Incorrect copying usually happens due to wrong field names, improper loop boundaries, or variable scope issues in your JavaScript. Ensure your loop iterates backward (from the bottom row up to the target row) so you do not overwrite data before it gets copied.

How do I find the row number of the clicked button in Acrobat JavaScript?

You can determine the row number by extracting it from the button's field name using JavaScript string manipulation methods (like split or substring), assuming your buttons are named sequentially (e.g., 'AddRowButton_3').

Can I insert an empty column instead of a row using JavaScript?

Yes, but the logic differs significantly. You must confirm whether your form structure requires shifting fields horizontally (columns) or vertically (rows) and adjust your loop's field referencing accordingly to match the column names.

Does WPS Office support interactive PDF forms?

Yes, WPS Office includes a robust PDF editor that supports viewing, filling, and basic editing of interactive PDF forms, making it a highly compatible alternative for managing standard PDF documents.