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

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

New Here ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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

Views

1.7K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 15, 2022 Jul 15, 2022

Votes

Translate

Translate
Community Expert ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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

event.target.value = "";

Votes

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
community guidelines
Community Expert ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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 = "";

 

Votes

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
community guidelines
New Here ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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

Testing on "Job Name" field:

Mendelhouse_0-1657823021309.png

General properties:

Mendelhouse_1-1657823066920.png

 

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

Mendelhouse_2-1657823113722.png

 

Where I put your suggestion:

Mendelhouse_3-1657823135512.pngMendelhouse_4-1657823152941.png

 

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

 

 

 

Votes

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
community guidelines
Community Expert ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

Remove the validation script and try it again.

Votes

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
community guidelines
New Here ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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?

Votes

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
community guidelines
Community Expert ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

Yes. Use the On Blur event with this code:

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

Votes

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
community guidelines
New Here ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
Community Expert ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

The code I provided will do that.

Votes

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
community guidelines
New Here ,
Jul 15, 2022 Jul 15, 2022

Copy link to clipboard

Copied

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

 

 

Mendelhouse_1-1657905126651.png

Mendelhouse_2-1657905158058.png

 

I see this (good):

Mendelhouse_3-1657905213751.png

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. 

 

 

 

Votes

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
community guidelines
Community Expert ,
Jul 15, 2022 Jul 15, 2022

Copy link to clipboard

Copied

Votes

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
community guidelines
New Here ,
Jul 15, 2022 Jul 15, 2022

Copy link to clipboard

Copied

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

Mendelhouse_0-1657906355913.png

 

Thanks!

Votes

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
community guidelines
New Here ,
Jul 15, 2022 Jul 15, 2022

Copy link to clipboard

Copied

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

 

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

 

3) Edit each JavaScript separately:

Mendelhouse_2-1657907915889.png

 

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.

Votes

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
community guidelines
New Here ,
Nov 16, 2023 Nov 16, 2023

Copy link to clipboard

Copied

This was superhelp!!! THANK YOU!!

Votes

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
community guidelines
New Here ,
Mar 13, 2024 Mar 13, 2024

Copy link to clipboard

Copied

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?

Votes

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
community guidelines