How to Clear Default PDF Form Field Values on First Click
Question details
The user needs a script to clear a default placeholder value (e.g., "none") in a PDF form field only the first time it is clicked, ensuring subsequent user input is not deleted.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms where text fields have default placeholder text that needs to vanish when the user clicks to type.
- Observed behavior
- The original script clears the field on every click due to syntax errors, specifically an invalid semicolon after the if statement and unnecessary else logic, which erases user-entered text.
Ensure you have access to a PDF editor that supports JavaScript form actions and that your document is currently in form editing mode.
Apply Correct JavaScript to a Mouse Action
Use a corrected JavaScript snippet on a mouse-up or mouse-down action to clear the default value without affecting user input.
When a script contains an invalid semicolon right after an 'if' statement, the condition is bypassed, causing the clearing action to execute every time the field is clicked. By correcting the syntax and removing unnecessary 'else' logic, the script will only clear the field if it contains the exact default value.
Right-click the specific text field in your PDF editor's form creation mode and select 'Properties' from the context menu.
Go to the 'Actions' tab, choose 'Mouse Up' (or 'Mouse Down') as the trigger, and select 'Run a JavaScript' as the action type.
Add the following exact script: if (event.target.value == "none") { event.target.value = ""; } (Replace "none" with your actual default placeholder text).
Click 'OK' to save the script, close the properties dialog, and exit form editing mode to test the field. The default text should now clear on the first click but retain your custom input afterward.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to easily create interactive forms, edit text fields, and manage document properties efficiently for a smooth user experience.
- 1. Open PDF in WPS Office: Launch WPS Office and open your PDF document to begin editing.
- 2. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon to access all interactive field creation tools.
- 3. Add or Edit Text Fields: Click 'Text Field' to insert a new box or double-click an existing field to modify its properties and default text.
- 4. Save the Document: Once your form fields are configured, click 'Save' to ensure all interactive elements function correctly for your end users.

Frequently Asked Questions
Why does my PDF form field clear every time I click it?
This usually happens due to a syntax error in your JavaScript, such as a misplaced semicolon right after an 'if' condition. This forces the clearing script to run regardless of the field's current value. Removing the semicolon and using the exact condition checking the target value fixes the issue.
Can I use 'Mouse Down' instead of 'Mouse Up' for this script?
Yes, both triggers work for this script. However, 'Mouse Up' is generally recommended for user interfaces because it allows the user to cancel the action by moving their cursor away before releasing the mouse button.
How do I set a default value for a PDF text field initially?
In form editing mode, open the field's Properties dialog, go to the 'Options' tab, and enter your desired placeholder text (like 'none' or 'Enter text here') in the 'Default Value' text box.




