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.
 
 

7 Comments

  • 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!

  • 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.

  • 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?

  • 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.

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

  • 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

  • I think the easiest way to do -
    Open SPD > EditForm.aspx > in code find standard toolbar webpart code > Make the Control Mode to "New" which will get rid of "Delete Item"

Comments have been disabled for this content.