Skip to main content
Participant
July 13, 2018
Answered

Show Default Value in Text Field Until User Inputs Data

  • July 13, 2018
  • 7 replies
  • 54573 views

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.

Correct answer worknetd97360590

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!

7 replies

Participant
December 19, 2023

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 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:

if(event.target.value==event.target.defaultValue)event.target.value="";

 

- Same steps but now under On Blur instead of On Focus, select action Run a JavaScript, click Add...

- Paste the following:

if(event.target.value=="")event.target.value=event.target.defaultValue;

Bernd Alheit
Community Expert
Community Expert
December 19, 2023

Why does you post copies of replies?

Participant
July 27, 2021

Is it possible to have this script work on a text box with the "multiple lines" option selected? Mine doesn't work if it is a large text field with multiple lines option.

Bernd Alheit
Community Expert
Community Expert
July 27, 2021

What script does you use?

Participating Frequently
November 6, 2020

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

Bernd Alheit
Community Expert
Community Expert
November 6, 2020

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

Participant
March 19, 2020

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?

Participant
February 10, 2020

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

Inspiring
July 14, 2018

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;

}

Participant
July 16, 2018

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.

try67
Community Expert
Community Expert
July 16, 2018

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

Wellsource
Participating Frequently
July 13, 2018

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.

try67
Community Expert
Community Expert
July 14, 2018

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