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

Want JS Form Field Name to Disappear when clicking into text field

New Here ,
Jul 14, 2022 Jul 14, 2022

I followed the instructions on this thread: https://community.adobe.com/t5/acrobat-discussions/pdf-text-field-form-label/m-p/3137258#M7006 where George_Johnson gave great info on how to get form fields to display the tooltip value by default. 

 

I am using this JS on a free text field:

 

if (!event.value) {

event.value = event.target.userName;

}

 

In it's default state (Tool Tip populating inside the text field), it is showing properly, printing properly, and saving properly.  What I please need help with is this: I want the text to disappear when the user clicks into the field to enter their own custom text.  Currently, when you click into the field, the text remains and you have to select it/delete it before typing.  Is this possible?

 

THANK YOU 

TOPICS
PDF forms
3.1K
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 ,
Jul 15, 2022 Jul 15, 2022
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 ,
Jul 14, 2022 Jul 14, 2022

As the field's On Focus event enter this code:

event.target.value = "";

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 ,
Jul 14, 2022 Jul 14, 2022

Keep in mind, though, that this code will also clear any input the user enters into the field, which you might not want to do... To avoid that you can change it to the following:

 

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

 

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 ,
Jul 14, 2022 Jul 14, 2022

Thank you for the response!  This doesn't seem to work for me.  Screenshots below.

Testing on "Job Name" field:

Mendelhouse_0-1657823021309.pngexpand image

General properties:

Mendelhouse_1-1657823066920.pngexpand image

 

JS I have in place to bring the Tool Tip in as the prepopulated text:

Mendelhouse_2-1657823113722.pngexpand image

 

Where I put your suggestion:

Mendelhouse_3-1657823135512.pngexpand imageMendelhouse_4-1657823152941.pngexpand image

 

But when I click into the field, the default text doesn't go away (hard to take a screenshot of this). 

 

 

 

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 ,
Jul 14, 2022 Jul 14, 2022

Remove the validation script and try it again.

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 ,
Jul 14, 2022 Jul 14, 2022

Thank you!  Getting closer!  If I click into the field, the default text dissappears.  However, if I click out of it (without entering anything) the original text does not return.  Is this possible?

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 ,
Jul 14, 2022 Jul 14, 2022

Yes. Use the On Blur event with this code:

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

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 ,
Jul 14, 2022 Jul 14, 2022

Stated another way, if the entry is Null, I want the Tool Tip name to appear in the field. If the cursor is active in the box, or if the user has entered any text, I want the tool tip name to be gone.

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 ,
Jul 14, 2022 Jul 14, 2022

The code I provided will do that.

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 ,
Jul 15, 2022 Jul 15, 2022

I just cannot get this to work.  Using your suggested code:

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

 

And an onptional "default value":

Mendelhouse_0-1657905105185.pngexpand image

 

 

Mendelhouse_1-1657905126651.pngexpand image

Mendelhouse_2-1657905158058.pngexpand image

 

I see this (good):

Mendelhouse_3-1657905213751.pngexpand image

But when i click into it, it doesn't clear.  The default value remains and I have to delete it all manually before entering what I want. 

 

 

 

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 ,
Jul 15, 2022 Jul 15, 2022
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 ,
Jul 15, 2022 Jul 15, 2022

I'll read that.  Although I don't understand how this is not an "on blur" event? 

Mendelhouse_0-1657906355913.pngexpand image

 

Thanks!

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 ,
Jul 15, 2022 Jul 15, 2022

This was exactly what I wanted.  I'm retyping it here for others in the future.  This is for a text field:

 

1) Under "Options", set your Default Value.  In my case, I'm using "Job Name"

Mendelhouse_0-1657907765987.pngexpand image

 

2) On the "Actions" tab, add two separate actions.  The first is an "On Focus" to "Run a JavaScript" and the second is an "On Blur" to "Run a JavaScript". 

Mendelhouse_1-1657907873043.pngexpand image

 

3) Edit each JavaScript separately:

Mendelhouse_2-1657907915889.pngexpand image

 

4) For "On Focus" use:

if (event.target.value==event.target.defaultValue) {
event.target.value = "";
event.target.textColor = color.black;
}

 

and for "On Blur" use:

if (event.target.value=="") {
event.target.value = event.target.defaultValue;
event.target.textColor = color.ltGray;
}

 

In each of those, the last line of code controls the color of the default/entered text.  The default text is lighter Gray and if text is entered, it is black.

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 ,
Nov 16, 2023 Nov 16, 2023

This was superhelp!!! THANK YOU!!

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 ,
Mar 13, 2024 Mar 13, 2024
LATEST

Thank you!! What if we have multiple fields with the same field name, how can I prevent the gray text from dissapearing in all of these fields at once?

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