Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Delete default value of text field when clicked

Community Beginner ,
Jul 30, 2024 Jul 30, 2024

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

TOPICS
JavaScript , PDF , PDF forms
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jul 30, 2024 Jul 30, 2024

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;

}

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2024 Jul 30, 2024
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 30, 2024 Jul 30, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2024 Jul 30, 2024

The code I posted in that thread also removes the default value when you enter the field.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 30, 2024 Jul 30, 2024

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.

screenshot.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2024 Jul 30, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2024 Jul 30, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2024 Jul 30, 2024

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;

}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 30, 2024 Jul 30, 2024

That's it! It works. I never thought to put the script under format.

 

Thank you very much and have a nice day!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 15, 2025 Jan 15, 2025
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines