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

Is there a way to format instructional text to my text field that disappears when clicked?

Community Beginner ,
Jan 11, 2018 Jan 11, 2018

I have the prompt text figured out using this script taken from this forum: Is there a way to add instructional text to my text field that will disappear when clicked? (PDF For...

// Custom Format script for text field

if (!event.value) {

event.value = "Instructional text goes here";

event.target.display = display.noPrint;

} else {

event.target.display = display.visible;

}

Is their a way to change the prompt text's size and make it different from the type size I have set for them to fill out in the form. I want the type size of the prompt to be smaller than what size they use to fill it out.

TOPICS
PDF forms
19.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 ,
Jan 11, 2018 Jan 11, 2018

Why yes there is, and your code is already setup for adding it.  The "display" is a property of the text field object, and it is being set one way for the help text, and another way when the user enters the text. The text size is also a property of the text field object and it can be set in the same way.

// Custom Format script for text field

if (!event.value) {

event.value = "Instructional text goes here";

event.target.display = display.noPrint;

event.target.textSize = 12;

} else {

event.target.display = display.visible;

event.target.textSize = 9;

}

You could also set the size on the keystroke event, or the OnFocus event, to capture the moment the user starts typing in the field.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Sep 09, 2020 Sep 09, 2020

This is a form text 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
New Here ,
Sep 09, 2020 Sep 09, 2020

So is that a "yes - it can be done" Or "No - it cannot be done"

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 ,
Sep 09, 2020 Sep 09, 2020

I don't know.

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 ,
Sep 09, 2020 Sep 09, 2020

Yes, it can be done. You would need to write a script to iterate over all the fields in the file (using numFields and getNthFieldName), check which ones are text fields (using getField and the type property) and then apply the code to them as the Format script (using the setAction method).

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
New Here ,
Apr 01, 2025 Apr 01, 2025

Hello just chiming in here to ask a question, can I add multiple forms like this in one document? LIke if I did an instructional text for Your Phone Number, could I then use the same script for say Your Email, and just change the intructional text for a different 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 Expert ,
Apr 01, 2025 Apr 01, 2025

Do you mean you want to use the same string for both fields, and be able to edit it in one place, and have it automatically apply to all of them?

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 ,
Apr 01, 2025 Apr 01, 2025
LATEST

Yes, you can do it that way. Or you could turn the code into a document level function, where the text is an input to the function, then call that function in all of the "format" scripts where it is needed. 

Note that this script replaces any built-in formatting. So, if you want the field formatted in some specific way, then you'll need to create a custom formatting script to add to the code. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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