Wednesday, October 6, 2010

Hide SharePoint List Items from New Form or Edit Form without SP Designer

So, what if you want to hide fields from the SharePoint list without tempering the list in SP Designer. Here is the Script.... J

  1. Open the NewForm.aspx or EditForm.aspx
  2. "&PageView=Shared&ToolPaneView=2" Add this text in the url and you can open the page in edit mode
  3. Add the CEWP and Click on the source Editor

And put the below script in it...

<script language="javascript" type="text/javascript">
function findacontrol(FieldName)
var arr = document.getElementsByTagName("!");
// get all comments
for (var i=0;i < arr.length; i++ )
// now match the field name
if (arr[i].innerHTML.indexOf(FieldName) > 0)
{ return arr[i]; }
function hideFields()
var control = findacontrol("CustomerID");"none";

See, the script is pretty simple, you can push your own Function on the page load and then it will call hideFields() Function which will find out the Control name from the page's HTML and set that display to "none", its done.

No comments: