Show greyed out text in field & vanish once entered

Community Alums
Not applicable

Hi,

 

I want to add a greyed text on field on front end form which must be displayed already inside field when form is loaded ,also it must be vanished once text is entered on field. PFA for reference (Highlighted Text).

4 REPLIES 4

Robbie
Kilo Patron
Kilo Patron

Hi @Community Alums,

 

This is easily achieved and the solution differs depending on the type of field type and form you're wanting to implement this on.

 

If (based on your screen shot) it's a catalog item and variable, simple enter the text within the "Example text" field on the variable attributes. (Screen shot below)

 

If it's a 'task' form such as incident for example, you'd have to handle it with something like a simple onLoad Client Script as below.

 

Variable:

Screenshot 2024-09-20 at 14.00.23.png

 

Client Script:

 

function onLoad() {
    var field = g_form.getElement("short_description"); //name of field where you wish to display the palceholder text
    if (field) {
        field.setAttribute('placeholder', 'Enter Short Description here...'); //change the text accordingly for your needs
        }
}

 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Community Alums 

 

Seems you want to add this text on variable

 

AGLearnNGrow_0-1726833069366.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Sid_Takali
Kilo Patron
Kilo Patron

Hi @Community Alums It is called a Placeholder and you can add it in Example Text Field on your Variable.

Sid_Takali_0-1726833634005.png

 

It worked fine.

Thanks a lot