PDF Editing Issues

How to Open a Dynamic URL with a PDF Form Text Field and Button

Algirdas JasaitisAlgirdas Jasaitis Nov 2, 2026 869 views

Question details

Create an interactive PDF form consisting of a text field and a button that appends the user's input to a predefined URL and opens the final link in a web browser.

How to Open a Dynamic URL Using a PDF Form Text Field and Button
Product
PDF Editor
Device & OS
not provided
Scenario
Adding a custom search or dynamic query submission button inside an interactive PDF document.
Observed behavior
A user needs a way to read a text field's value, combine it with a base URL, and trigger the default web browser to launch the combined web address upon clicking a button.
Before you start

Ensure your PDF editing software supports creating form fields and executing document-level or button JavaScript actions.

Solution 1Recommended

Adding Custom JavaScript to a PDF Form Button

Use a simple JavaScript snippet tied to the button's action to read the text field's value, append it to the hidden base URL, and launch the browser.

This solution relies on the built-in JavaScript engine available in standard desktop PDF editors to dynamically capture user input and trigger external links.

1
Create the text field

Use your PDF editor's form tools to add a new text field to your document. Open its properties and name it exactly 'SearchTerm'.

2
Create the submit button

Add a Push Button form field to the document, which users will click to trigger the search or submission.

3
Add a JavaScript action

Right-click the button and open its Properties. Navigate to the 'Actions' tab, select 'Mouse Up' as the trigger, choose 'Run a JavaScript' as the action, and click 'Add'.

4
Enter the script

Input the following code into the editor window: var cSrchTerm = this.getField("SearchTerm").value; var cHiddenURL = "http://www.yourwebsite.com/?q="; app.launchURL(cHiddenURL + cSrchTerm);

5
Save and test

Close the properties dialog and save the PDF document. Type a query into the text field and click the button to verify that your default web browser opens the correct dynamically generated URL.

Adding Custom JavaScript to a PDF Form Button
Handling Special Characters: If you expect users to enter spaces or special characters, wrap the text field value in the encodeURIComponent() function in your script to prevent broken URLs.
Interactive PDF Form Management

Edit and Manage PDF Forms Easily with WPS Office

WPS Office provides comprehensive PDF tools, allowing you to easily view, fill, and manage interactive PDF forms without the need to switch to expensive software.

  1. 1. Download and Install WPS Office: Get the latest version of WPS Office for free from the official website and launch the application.
  2. 2. Open your PDF Form: Drag and drop your interactive PDF document into WPS Office to open it.
  3. 3. Fill and Interact: Navigate through the PDF, input text into interactive fields, click form buttons, and securely save your completed document.
Easily view, fill, and sign interactive PDF forms and documentsHighly compatible with standard PDF formats generated by Adobe AcrobatLightweight, fast, and user-friendly interface for seamless document handlingBuilt-in PDF conversion tools to extract and share form data securely
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't the web browser opening when I click the PDF button?

Your PDF viewer may have security settings that block external links or JavaScript execution by default. Check your application's Trust Center or security preferences to allow the document to launch external URLs.

Can I use this JavaScript PDF form on mobile viewers?

Mobile PDF viewers often have limited or no support for custom JavaScript execution. This method is best suited for desktop PDF applications. For broad mobile compatibility, consider providing a standard, static hyperlink instead.

How do I encode the search term to handle spaces in the URL?

You can modify your JavaScript to URL-encode the string. In the script, change 'cSrchTerm' to 'encodeURIComponent(cSrchTerm)' when appending it to the base URL. This safely translates spaces into '%20' for the web browser.