Tuesday, April 28, 2009

JavaScript funtion to hide fields on Newform.aspx/Editform.aspx

•TAGNAME: HTML element that is being rendered ("SELECT", "INPUT"...)

•IDENTIFIER: SharePoint field type identifier ("TextField", "DropDownChoice"...)

•FIELD NAME: Display name of the field (e.g. "Status", "Customer Name"...)



Script starts...


_spBodyOnLoadFunctionNames.push("hideFields");

function hideFields() {
var control = getTagFromIdentifierAndTitle("TAGNAME","IDENTIFIER","FIELD NAME");
control.parentNode.parentNode.parentNode.style.display="none";
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
return tags[i];
}
}
return null;
}

Script ends...

you can also refer to this link

No comments: