Abhishek Bhowmick | SharePoint Blog

Hide specific columns from Newform.aspx and Editform.aspx page

Posted in Sharepoint by Abhishek Bhowmick on June 22, 2011

Many a times you come across a requirement where users would like to hide a column from the Newform.aspx and Editform.aspx pages however would like to retain the columns for the SharePoint list/library. This is possible OOB. Here is how:

  • Open Newform.aspx or Editform.aspx page in edit mode. You can find more info about how to this in my previous post.
  • Add a Content Editor Web Part on the page and add following javascript code to the source editor. You may change the column names in the code based on the names of the columns in the list/library you are working on. 
<script language="javascript" type="text/javascript"> 
_spBodyOnLoadFunctionNames.push("hideFields"); 
function findacontrol(FieldName) 
{ 
 var arr = document.getElementsByTagName("!"); 
 for (var i=0;i < arr.length; i++ ) 
 { 
 if (arr[i].innerHTML.indexOf(FieldName) > 0) 
 { 
 return arr[i]; 
 } 
 } 
} 
function hideFields() 
{ 
 var 
 control = findacontrol("Column Name 1"); 
 control.parentNode.parentNode.style.display="none"; 
 control = findacontrol("Column Name 2"); 
 control.parentNode.parentNode.style.display="none"; 
} 
</script>
 

I wanted to extend a word of thanks to my colleagues I work with – Rohan Chittyal, Nidhi Gupta and Amol Ghuge.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: