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:
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.targe
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 accept user input, which can be alphabetic characters, numbers, or both.
Specifies the text that appears until the user overwrites it by typing in the field. Enter the default value by typing in this option.
Copy link to clipboard
Copied
Did you set the field's Format to anything other than None?
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;
}
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.
Copy link to clipboard
Copied
Can you share the file with us (via Dropbox, Google Drive, Adobe Cloud, etc.)?
Copy link to clipboard
Copied
What happens when you use the code?
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.
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!
Copy link to clipboard
Copied
The Focus/Blur script works great!
Thank you!
Elise
Copy link to clipboard
Copied
Okay I figured out how to get the code to input - however I need the text disappear when they tab over to start typing. Currently with the two codes entered they have to highlight and delete the text before typing.
I also had a problem when printing - when I go to print it doesn't print any of the saved information.
Copy link to clipboard
Copied
I tried useing the directions you provided and came up short. Once I add the text in I have the option to Cancel or Go to - If I close the box nothing saves and if I choose go to nothing saves either - any advice??
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.
Copy link to clipboard
Copied
In that script, the common properties uner the general tab get overwritten - so if you want the default text to actually print on the form you need to adjust the script. It is quite simple - change the 4th line in the script above
from
event.target.display = display.noPrint;
to:
event.target.display = display.visible;
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.
Copy link to clipboard
Copied
Just wondering if you found a solution to your question above about having the default field text a different colour to the users typed answer colour? I'm having the same issue and can't figure it out!
Copy link to clipboard
Copied
This is what works for me:
Add JavaScript to Text Field
(Properties>Format>select Custom from dd list and add to Custom Format Script)
if (!event.value) {
event.value = "Default text";
event.target.textColor = color.dkGray;
event.target.textSize = 8;
} else {
event.target.textColor = color.black;
event.target.textSize = 9;
}
In the above:
The default text color would be dark gray (color.dkGray) and the text size would be 8 pt.
For the users typed answer, the text color black (color.black) and the text size would be 9 pt.
I hope this is helpful.
Copy link to clipboard
Copied
Where is this added to the "Enter Name Here" script you mentioned above?
Copy link to clipboard
Copied
Hey,
In the above the code there would completely replace it. I made a minor edit to the posted text to hopefully clarify it for you.
if (!event.value) {
event.value = "Your Text Goes Here";
event.target.textColor = color.dkGray;
event.target.textSize = 8;
} else {
event.target.textColor = color.black;
event.target.textSize = 9;
}
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
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?
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?
Copy link to clipboard
Copied
You can use a color array. Details are in the Acrobat Javascript Reference.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
What script does you use?