Edit the title property of a field to add custom tooltip

By Alexander

29.10.2009 Update: I have written a new article on how to add HTML-style tool tip – read it here.


I got a request for a method of adding a custom mouse-over tool tip on a field in a SharePoint form. Here is a quick example.

As always we start like this:
Create a document library to hold your scripts (or a folder on the root created in SharePoint Designer). In this example i have made a document library with a relative URL of “/test/English/Javascript” (a sub site named “test” with a sub site named “English” with a document library named “Javascript”):
IMG

The jQuery-library is found here. The pictures and the sourcecode refers to jquery-1.3.2.min. If you download another version, be sure to update the script reference in the sourcecode.

Add a CEWP below your list-form like this:IMG

And add this code:

<script type="text/javascript" src="/test/English/Javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
fields = init_fields();

$(fields['Title']).find('input').attr('title','This is a new mouse-over tooltip');

function init_fields(){
  var res = {};
  $("td.ms-formbody").each(function(){
	  if($(this).html().indexOf('FieldInternalName="')<0) return;
	  var start = $(this).html().indexOf('FieldInternalName="')+19;
	  var stopp = $(this).html().indexOf('FieldType="')-7;
	  var nm = $(this).html().substring(start,stopp);
	  res[nm] = this.parentNode;
  });
  return res;
}
</script>

The tooltip should look like this:
IMG

Ask if this example is not enough.

Alexander

12 Responses to “Edit the title property of a field to add custom tooltip”

  1. larry Says:

    Great, this is very clean and simple. Using the title tag for the field. How can we convert this to build a true tool tip that is customizable, and we get it on mouse over of the label also?

  2. Alexander Says:

    Hi,
    Where would you like to customize the tooltip? – in a separate list?
    If so – you will find an example of howto do this in this post:
    Get variables in a script from another list

    To have the tooltip on the entire row, edit the code like this:

    $(fields['Title']).attr('title','This is a new mouse-over tooltip');
    

    Alexander

  3. larry Says:

    Yes I remember that post. another solid hit. I have been trying to build a tool tip that you could customize the terxt, by adding color for formating the text. Something you could set a position of the text, but not get in the way of typing in the field. Also maybe make it not on mouseove. but adding a small image that can be clicked for details and have the popup with the text. The best case would be to have the ability to pull the tooltip text from another list. but for now I am just trying to create a customizable tooltip with color format and position.

  4. Alexander Says:

    Once again your prayers are answered :-)
    Add HTML mouseover tooltip

    Alexander

  5. larry Says:

    I am not worthy to be in your presence

  6. Amit Says:

    Hi Alexander,

    how can i display the tooltip for sahrepoint calendar. i.e i need to dispaly the mouse over message for sharepoint calendar event item.

    any way to do that?

    Thanks
    Amit

  7. Alexander Says:

    Hi Amit,
    What kind of information do you want to display in the tooltip? – is it information from the list item itself or some kind of generic information?

    Alexander

  8. Amit Says:

    Hi Alexander,

    i have a column called Course description. I want to display that information. So the information is from list only.

    Amit

  9. Alex Says:

    Hello Alex.
    You have great work and I am looking forward to utilizing your code. My request is similar to Amit’s in that I have a table with a title and message column. On the “dashboard” page, I am only displaying the title column and would like to have a tooltip which would display the content of the message column which corresponds to that item. Please let me know if you have a solution for this.
    Thanks again!
    Alex

    • Alexander Says:

      Hi,
      To use this solution Preview metadata in list view on mouseover, you have to show the field “Title (linked to item)” or “Title (linked to item with edit menu)”.

      This has to do with the preview reading the URL from this field. If you use the “plain” Title-field, you do not get this link and therefore no preview.

      Alexander

Leave a Reply