I love my day job
Quick fixes: Removing the Delete button from a SharePoint 2007 OOTB edit form - SharePoint Skater

SharePoint Skater

Custom control and client script aficionado, neck-deep in a simmering SharePoint stew.

Quick fixes: Removing the Delete button from a SharePoint 2007 OOTB edit form

I know what you're thinking.  "If you don't want them to delete the item, why don't you just create a special permission level without the ability to do that?"

As it turns out, the poser of this particular puzzlement *did* in fact want the user to have delete permissions... but only via workflow.  Yes, you can write a custom workflow that impersonates, blah blah blah, but this happened to be the quick and dirty solution for his immediate needs.

  1. Go to the Edit form.
  2. Pull down Site Actions -> Edit Page.
  3. Add a Content Editor Web Part (my favorite WP ever).
  4. Pull down Edit -> Modify Shared Web Part.
  5. Click the Source View button.
  6. Add the following JavaScript:
var aList=document.getElementsByTagName("a");
   for(i=0;i<aList.length;i++) {
    if(aList[i].innerHTML=="Delete Item") {
    aList[i].parentElement.parentElement.style.display="none";
    }
   }
 
Note:  If you are using WSS instead of MOSS, you can tweak this to check for the title attribute instead of innerHTML, i.e.
   if(aList[i].title=="Delete Item")
 
     7.Save, OK, etc.
 
 

Comments

Lisa said:

Hi,

I'm trying to use that code on our site which is a WSS 3.0 site.

I need to hide the Delete Item option in my EditForm.aspx and I don't succeed at doing this with this code; is it supposed to work in WSS 3.0?

Thanks!

# November 23, 2010 8:28 AM

PeterBrunone said:

Hi Lisa,

Thank you for bringing that up!  I've added a note about your question; in short, you need to check for the title attribute instead of the innerHTML attribute.

# March 1, 2011 12:51 PM

Vergil said:

Spec is working fine when called from the button click event.

However when the form(Displayform/editform) loads the spec is unable to locate "Delete Item"

Can you plz help me out?

# May 4, 2011 8:28 AM

PeterBrunone said:

Hi Vergil,

   Could you explain a bit further?  I'm not sure what you mean by "spec" or why it needs to locate the Delete button.

# May 4, 2011 3:22 PM

Jason Vickers said:

This, sir, was exactly what I was looking for.  Thanks for putting this out there.

# July 5, 2011 10:05 AM

sateesh said:

This code is not working for me in a custom list editform.aspx or allitems.aspx forms in sharepoint 2010

Please help me

Thanks in Advance

Sateesh babu

# September 28, 2011 6:59 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)