Copy link to clipboard
Copied
hello everyone,
I have several fields in a PDF form with the following function:
if(event.value == "")
{
event.value = "Company Name";
event.target.display = display.noPrint;
}
else
event.target.display = display.visible;
If the default value is not changed, then the text is not printed and that works as intended.
Now I want to make the fields a bit more user-friendly by removing the default text when clicking or tabbing, so that the user can enter their text directly without having to delete the default text beforehand. If they don't enter any new text or click on another field, the default text should appear again. Has anyone here had a similar case?
Many thanks in advance
Copy link to clipboard
Copied
It's not a validation script. It's a Format script. Remove the validation script and enter this format script:
if (!event.value) {
event.value = "Instructional text goes here";
event.target.display = display.noPrint;
} else {
event.target.display = display.visible;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you, but this just changes the text color.
It would be better if the text was removed and not just the color of the text was changed. The background color of each field is a light gray. If nothing is entered in the fields, you will see where you need to fill something in on the printed document.
Copy link to clipboard
Copied
The code I posted in that thread also removes the default value when you enter the field.
Copy link to clipboard
Copied
When I add your code nothing changes. The text "Company Name" remains in the text field when clicked. The same thing happens when I insert your code under Actions - On Focus and On Blur.
Copy link to clipboard
Copied
The code I posted in that thread is actually two scripts, one for the On Blur event and one for On Focus, as is specified in the comments.
Copy link to clipboard
Copied
There's nothing in the answer that is marked correct in that link about changing the text color. Make sure it is entered as a custom format script.
Copy link to clipboard
Copied
It's not a validation script. It's a Format script. Remove the validation script and enter this format script:
if (!event.value) {
event.value = "Instructional text goes here";
event.target.display = display.noPrint;
} else {
event.target.display = display.visible;
}
Copy link to clipboard
Copied
That's it! It works. I never thought to put the script under format.
Thank you very much and have a nice day!
Copy link to clipboard
Copied
This didn't work for me. I did the following instead
Here’s how to set it up in a Mac:
Steps:
1.Open the Form in Adobe Acrobat:
•Open your PDF file in Adobe Acrobat Pro.
•Go to Tools > Prepare Form.
2.Select the Text Field:
•Click on the text field you want to modify.
3.Add JavaScript:
•Right-click on the text field and choose Properties.
•In the Text Field Properties dialog, go to the Actions tab.
•Set up an action to clear the default value when the field is clicked.
4.Configure the Action:
•From the Select Action dropdown, choose Run a JavaScript.
•Click Add and enter the following JavaScript code:
--
if (event.target.value == "Default Value") {
event.target.value = "";
}
---
Replace "Default Value" with the actual default text in the field.
•Click OK to save.
5.Prevent Resetting When Clicking Outside (Optional):
•To ensure the field retains the cleared value when the user clicks away, verify the Default Value setting in the Options tab. Leave it blank if you don’t want it to reappear.
6.Test the Form:
•Close the properties dialog and test the field by clicking on it in the form. The default text should clear when clicked.
Notes:
•This script checks whether the field’s current value matches the default text. If it does, it clears it.
•If you have multiple fields with the same default text, repeat the process for each field or use document-level scripts to apply the logic universally.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now