PDF Editing Issues

How to Launch a Custom URL with PDF Form Values Using JavaScript

Elise WilliamsElise Williams Nov 5, 2026 869 views

Question details

How to retrieve a user-entered value from a PDF form field and use it to dynamically construct and launch a custom URL via a JavaScript button action.

Launch a Custom URL with a PDF Form Value Using JavaScript
Product
PDF
Device & OS
not provided
Scenario
Creating an interactive PDF document where a push button or text field action launches a URL containing dynamic user input, such as a custom tabletop RPG dice command.
Observed behavior
The user needs the correct JavaScript syntax to extract the field data and concatenate it to a base URL string, ensuring the script executes properly without external text editor saving issues.
Before you start

Ensure your PDF editor supports JavaScript execution and interactive form creation. Verify the exact name of the text field from which you intend to retrieve the value.

Solution 1Recommended

Concatenate Field Values using app.launchURL

Extract the target form field's value using the getField method and combine it with your base URL string to launch the dynamic web or app request.

By using the native PDF JavaScript API, you can dynamically retrieve text inputted by the document user. You can then append this text to a static URL base to trigger customized web queries or local application commands (such as a 'talespire://' URL scheme).

1
Identify the target field name

Open your PDF form editor, right-click the text field you want to extract data from, and check its properties to note the exact field name (e.g., 'details_str_modifier').

2
Assign a JavaScript action to a button

Create a Push Button on your PDF. Open its Properties, navigate to the Actions tab, select 'Run a JavaScript' as the action type, and click Add.

3
Write the concatenation script

In the JavaScript editor window, define a variable to capture the input: var StrMod = this.getField("details_str_modifier").value; Then construct and launch the URL: app.launchURL("talespire://dice/d20+" + StrMod, true);

4
Save the script and document

Click OK to save the JavaScript changes directly in your PDF editor. If you are using an external editor like Atom to write your script, ensure the file is properly saved and synced with your PDF software before testing.

Concatenate Field Values using app.launchURL
Syntax Check: Pay close attention to spacing and quotation marks when concatenating strings (using the + operator) in JavaScript to ensure the final URL is formatted correctly.
Create Interactive PDFs with WPS

Easily Add JavaScript and Forms with WPS Office

WPS Office provides robust PDF editing capabilities, enabling you to effortlessly insert interactive text fields, configure push buttons, and add custom JavaScript actions to create dynamic document workflows.

  1. 1. Open your PDF: Launch WPS Office and open the PDF document you want to make interactive.
  2. 2. Navigate to Form Tools: Go to the 'Form' tab in the top ribbon menu to access the text field and push button insertion tools.
  3. 3. Insert Form Elements: Click 'Text Field' to add user input areas, then click 'Push Button' to place your interactive trigger.
  4. 4. Add JavaScript: Right-click the button, select Properties, go to Actions, and choose 'Run a JavaScript' to paste your custom app.launchURL code.
  5. 5. Test your document: Save the PDF file, exit form editing mode, and click the button to verify that the dynamic URL launches successfully.
Intuitive tools for designing advanced interactive PDF formsSeamlessly insert and configure custom JavaScript actionsHighly compatible with standard Adobe Acrobat PDF formatsLightweight, fast, and completely free to download
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my JavaScript executing when I click the PDF button?

Ensure that JavaScript is enabled in your PDF viewer's security preferences. Also, verify that the button's action trigger is correctly set to 'Mouse Up' rather than 'Mouse Down', which is the standard trigger for interactive buttons.

Can I use this method to pass multiple form values into a single URL?

Yes. You can declare multiple variables to retrieve different field values using this.getField("fieldname").value, and then concatenate all of them into a single URL string before calling app.launchURL.

Why didn't my JavaScript changes save when editing via an external app?

If you use an external editor like Atom to write your script, the changes will not take effect until the file is physically saved in that editor and your PDF program refreshes or detects those external changes. Writing the script directly in your PDF editor's native JavaScript console often prevents this synchronization issue.