How to Open a Dynamic URL with a PDF Form Text Field and Button
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.

- 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.
Ensure your PDF editing software supports creating form fields and executing document-level or button JavaScript actions.
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.
Use your PDF editor's form tools to add a new text field to your document. Open its properties and name it exactly 'SearchTerm'.
Add a Push Button form field to the document, which users will click to trigger the search or submission.
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'.
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);
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.

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. Download and Install WPS Office: Get the latest version of WPS Office for free from the official website and launch the application.
- 2. Open your PDF Form: Drag and drop your interactive PDF document into WPS Office to open it.
- 3. Fill and Interact: Navigate through the PDF, input text into interactive fields, click form buttons, and securely save your completed document.

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.




