Highlighted

Show Default Value in Text Field Until User Inputs Data

Community Beginner ,
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.

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!

TOPICS
PDF forms, Windows

Views

7.6K

Likes

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

Show Default Value in Text Field Until User Inputs Data

Community Beginner ,
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.

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!

TOPICS
PDF forms, Windows

Views

7.6K

Likes

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
Jul 13, 2018 2
Explorer ,
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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 13, 2018 0
Most Valuable Participant ,
Jul 14, 2018

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jul 14, 2018 0
Adobe Community Professional ,
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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 13, 2018 3
Community Beginner ,
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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 16, 2018 0
Most Valuable Participant ,
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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 16, 2018 0
Adobe Community Professional ,
Jul 16, 2018

Copy link to clipboard

Copied

What happens when you use the code?

Likes

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
Reply
Loading...
Jul 16, 2018 0
Community Beginner ,
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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 16, 2018 0
Community Beginner ,
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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 16, 2018 1
Explorer ,
Jul 16, 2018

Copy link to clipboard

Copied

The Focus/Blur script works great!

Thank you!

Elise

Likes

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
Reply
Loading...
Jul 16, 2018 0
Community Beginner ,
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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 28, 2020 0
New Here ,
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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 10, 2020 0
New Here ,
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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 18, 2020 0
New Here ,
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

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 06, 2020 0
Adobe Community Professional ,
Nov 06, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Nov 06, 2020 0