Show Default Value in Text Field Until User Inputs Data

Community Beginner ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

Okay, so... I'm trying to figure out how to have default text show in a form field/text field until the user clicks on it and inputs their own data. I don't want labels, I just want default values to be displayed in the fields.

I've read through so many forums, and they all have code along these lines:

if (event.target.value=="") {

   event.target.value = event.target.defaultValue;

   event.target.textColor = color.ltGray;

}

I've tried every suggestion I found, but it still doesn't work.

Using Acrobat XI Pro.

TOPICS
PDF forms, Windows

Views

15.4K

Likes

translate

Translate

Translate

Report

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

correct answers 1 Correct Answer

Community Beginner , Jul 16, 2018 Jul 16, 2018
Finally got it. I was trying to use the scripts I've seen for the entire form. I didn't know you had to set actions for the form fields.I'm going to break it down Barney style for the new users (like myself).- Add a text field to your form- View the text field's properties- Under the Options tab, enter the default text that you want to be displayed- Under the actions tab, select trigger On Focus, select action Run a JavaScript, click Add...- Paste the following:// On Focus script:if (event.targe...

Likes

translate

Translate

Translate
Explorer ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

Not an answer, but a similar question:

Per the Acrobat User Guide, and in previous versions of Acrobat, the Text Field Default Value could be defined in Properties: Options: Default Value. However, it is not working for me. I only get a Default Value of "0". I want my Default Value to be something like: "Enter Name" that goes away when the user clicks in the field.

I tried a script similar to that posted by OP.

Tooltip works fine.

Acrobat Pro DC on Windows 10.

Text Fields

Text fields accept user input, which can be alphabetic characters, numbers, or both.

     Default Value

Specifies the text that appears until the user overwrites it by typing in the field. Enter the default value by typing in this option.

Likes

translate

Translate

Translate

Report

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
Most Valuable Participant ,
Jul 14, 2018 Jul 14, 2018

Copy link to clipboard

Copied

Did you set the field's Format to anything other than None?

Likes

translate

Translate

Translate

Report

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
Adobe Community Professional ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

Remove that script from wherever you placed it and use the following custom Format script:

// Custom Format script for text field

if (!event.value) {

    event.value = "Your text goes here";

    event.target.display = display.noPrint;

} else {

    event.target.display = display.visible;

}

Likes

translate

Translate

Translate

Report

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 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

Wellsource --- I wish it was as simple as putting text under default value. I put the text that I would like, but it doesn't work.

George_Johnson --- Thank you for the reply, but this did not work for me.

try67 --- The format is None.

Likes

translate

Translate

Translate

Report

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
Most Valuable Participant ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

Can you share the file with us (via Dropbox, Google Drive, Adobe Cloud, etc.)?

Likes

translate

Translate

Translate

Report

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
Adobe Community Professional ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

What happens when you use the code?

Likes

translate

Translate

Translate

Report

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 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

I was assuming that any script you added/edited would take effect with existing form fields; it does not.

George_Johnson, I tried it again and then added a new field and there is a default value displayed.

I'm going to play around with this and post what my ultimate solution is, because right now there are a couple of issues.

Likes

translate

Translate

Translate

Report

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 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

Finally got it. I was trying to use the scripts I've seen for the entire form. I didn't know you had to set actions for the form fields.

I'm going to break it down Barney style for the new users (like myself).

- Add a text field to your form

- View the text field's properties

- Under the Options tab, enter the default text that you want to be displayed

- Under the actions tab, select trigger On Focus, select action Run a JavaScript, click Add...

- Paste the following:

// On Focus script:
if (event.target.value==event.target.defaultValue) {
 
event.target.value = "";
 
event.target.textColor = color.black;

}

- Under the actions tab, select trigger On Blur, select action Run a JavaScript, click Add...

- Paste the following:

// On Blur script:
if (event.target.value=="") {
  
event.target.value = event.target.defaultValue;
  
event.target.textColor = color.ltGray;
}

- Close the properties box

Your fields should now have the default value you set displayed in them. Selecting a text field will "erase" the default value and allow the user to enter their information. Deleting the information will cause the default value to be displayed again.

Thanks for all of the help, guys!

Likes

translate

Translate

Translate

Report

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 ,
Jul 16, 2018 Jul 16, 2018

Copy link to clipboard

Copied

The Focus/Blur script works great!

Thank you!

Elise

Likes

translate

Translate

Translate

Report

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 ,
Apr 28, 2020 Apr 28, 2020

Copy link to clipboard

Copied

This ladies and gentleman is exactly what I needed and what I believed the OP was looking for. You want temp text in the field to either show guidance to the end user as to what to place in the field OR you want additional direction for the field to be there until text is typed. 

 

Beautiful script. I greatly appreciate it.

 

TO be clear:

 

edit the field properties.

Click the format tab

Then where it says select format category form the drop-down select 'Custom'

where it says custom format scrip click Edit and enter the script below:

// Custom Format script for text field

if (!event.value) {

    event.value = "Your text goes here";

    event.target.display = display.noPrint;

} else {

    event.target.display = display.visible;

}

 

Where it says "Your Text goes here" change that to the starting text you want.

 

**Note** remove all other starting text you had already set and tried.

Likes

translate

Translate

Translate

Report

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 ,
Feb 20, 2021 Feb 20, 2021

Copy link to clipboard

Copied

George_Johnson--Thank you, this script works perfectly for my needs.

 

Just wondering if there is a way to specify the text color for JUST the default field text, while keeping the actual filled in type color the same as all other fields in the form (in my case black) within this script? I tried a few different ways, but it always changed the color for both the default text and the users typed answer. 

Likes

translate

Translate

Translate

Report

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
New Here ,
Feb 10, 2020 Feb 10, 2020

Copy link to clipboard

Copied

It almost works!

There appears one problem:

When opening the file the default text is shown. Clicking into the text field deletes the defualt text and allows me to type in my own text. Leaving the field with the mouse cursor results in showing my own text in the text field. Everything fine so far.

BUT: When clicking into the field again, my previous individual/ own text will be deleted! What means: If I click again into the filled field and decide that i don't want to change anything - my previously entered text it gone, deleted. How can I fix it?

 

Best wishes

Likes

translate

Translate

Translate

Report

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
New Here ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

This did not work for me. I have Build: 19.21.20061.361316

 

I added both of these lines in the actions menu and when I click on the box nothing changes, the default value shows and has to be deleted before I can enter text. 

 

Any ideas?

Likes

translate

Translate

Translate

Report

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 ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

Can i use a hex code for the color instead of "color.red" or "color.ltgray"? What would the code be?

Likes

translate

Translate

Translate

Report

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
Adobe Community Professional ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

You can use a color array. Details are in the Acrobat Javascript Reference.

Likes

translate

Translate

Translate

Report

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