- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2012 08:07 PM
I've created a function to add support for the HTML placeholder attribute. You can use it to include some extra helpful text in input fields:
It's real simple to use - just include a call to the function in an onLoad script with the name of the field/variable and the text you want displayed:
u_addPlaceholderAttribute('short_description', 'Enter a short description of the problem');
I've tested it in Chrome, Firefox and Opera on Windows 7 and it works. Of course it does not work in current version of IE, but it does work in the upcoming IE 10.
Here's the script:
function u_addPlaceholderAttribute(variableName, hint) {
try{
var fieldName = g_form.getControl(variableName).name.toString();
if (Prototype.Browser.IE) {
fieldName.placeholder = hint;
} else {
$(fieldName).writeAttribute('placeholder', hint);
}
} catch(err) {}
}
I've also attached it as an XML export of the function - just remove the ".txt" extension and import it into your instance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2014 01:10 PM
Just setting this answer as correct as the actual thread was not meant as a question and it cannot be changed because it came from the original Community site.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2017 04:01 PM
The script should be a global UI Script and not a Script Include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2018 01:20 PM
Hey Jim ,
i got a chance to use this script for one of my requirement . I tried it on catalog items it worked , i tried it on incident form it worked .
i observed that it works only for single line text fields and multi line texts fields . so any possibility to make it work for reference fields too ??
will this work on reference fields ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2018 02:28 PM
It actually does as is. Here's a screenshot of an Incident form:
And on a Catalog Item:
The trick is to use the full name of the input control for the reference field, like so - "sys_display.table_name.field_name" (e.g. sys_display.incident.caller_id).
For Catalog Variables, it's a little different - "sys_display.IO:sys_id_of_the_variable" (e.g. sys_display.IO:2a3947a10a0a020e007f12648f8790c0).
You can use your browsers "Inspect" or "Inspect element" function to get the proper names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2019 03:13 AM
Hi Jim,
I need to have placeholder text foe a field of type 'HTML'. Is there a way to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2019 03:10 AM
Sadly, I don't think this is possible for non string fields. I tried for Reference fields and HTML fields without success. We need to continue to convince ServiceNow to add HTML placeholder as a platform feature.
∴
Best regards from Switzerland
Shiva :¬,
If this reply assisted you, please consider marking it 👍Helpful.
This enables other customers to learn from this thread.