Wednesday, August 8, 2012

Hide column on SharePoint list forms - JavaScript

Hide column on Sharepoint Dispform.aspx, Editform.aspx, Newform.aspx using a JavaScript.
Copy the script on desired form under the
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server"> tag:

<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("hideFields");
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("Column-1");
control.parentNode.parentNode.style.display="none";

control = findacontrol(" Column-2");
control.parentNode.parentNode.style.display="none";
}
</script>

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...