Skip to main content
Participant
January 11, 2018
Answered

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

  • January 11, 2018
  • 3 replies
  • 22172 views

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 Forms)

// 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.

Correct answer Thom Parker

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.

3 replies

Participant
April 1, 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?

try67
Community Expert
Community Expert
April 1, 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?

Participating Frequently
September 9, 2020

Thanks. Now how do I apply this java script to all my text fields in one step? I want to avoid having to go to all my 300 comment boxes, open them and insert instructional text to my text field .

 

Bernd Alheit
Community Expert
Community Expert
September 9, 2020

You want the same instructions for all text fields?

Participating Frequently
September 9, 2020

Yes for all text fields

 

I am using the script below to add instructional text to my text field that will disappear when clicked. But the script is only valid for one box.


Now how do I apply this java script to all my text fields in one step? I want to avoid having to go to all my 300 comment boxes, open them and insert instructional text to my text field.


if (!event.value) {
event.value = "Instructional text goes here";
event.target.display = display.noPrint;
} else {
event.target.display = display.visible;
}

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
January 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
January 11, 2018

Hey Thom,

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. How would I do that? I'm very new to this.

Thom Parker
Community Expert
Community Expert
January 15, 2018

Add this to the custom Keystroke script on the field

if(!event.willCommit)

     event.target.textSize = 9;

It sets the text size to 9 at the moment the user types the first character in the field

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