Thursday, July 26, 2012

SharePoint 2010: Change the “Add New Item” (and other) messages for a web part

What we want : To change from “Add new item”:


JS Code :
<script>
var ABC = document.getElementsByTagName('XYZ');
var Counter = 0;
for (var j=0; j<ABC.length; j++)
{
  if (ABC[j].id == 'idHomePageNewItem')
  {
     Counter ++;
if (Counter == 2) { ABC[j].innerHTML='Click here to add team tasks' } } } </script>

Where should you add the code?

Add the code to the page using SharePoint Designer
  1. Edit the page using SharePoint Designer
  2. Find the “<asp:content” tag for PlaceHolderMain and then find the matching end tag (“</asp:content>”)
  3. Just before the end tag, add the JavaScript listed above
Or  add a Content Editor Web Part to the page.

ID’s used by web parts


Web Part Default message ID for “.getElementById” in the code below
Announcements Add new announcement “idHomePageNewAnnouncement” (changed in 2010)
Links Add new link "idHomePageNewLink" 
Calendar Add new event "idHomePageNewEvent"
Picture Library Add new picture “idHomePageNewItem”  *  (changed in 2010)
KPI List Add new item "idHomePageNewItem"  *  (changed in 2010)
Tasks Add new item "idHomePageNewItem"  *  (changed in 2010)
Project Tasks Add new item "idHomePageNewItem"  *  (changed in 2010)
Document Library Add new document "idHomePageNewDocument"  (changed in 2010)
Wiki Add new Wiki page "idHomePageNewWikiPage"   (changed in 2010)
Discussion Add new discussion "idHomePageNewDiscussion"  (changed in 2010)
Custom List Add new item “idHomePageNewItem” *   (changed in 2010)

Hide the “+” image?

If you want to get rid of the little icon just before the “New Item” text then just add one more line of code after where you change the message:      ABC[j].innerHTML='Click here to add team tasks';      ABC[j].previousSibling.previousSibling.style.display='none';

No comments:

Post a Comment