2009/03/02

Hide fields in NewForm.aspx without customization


You can use the following techniqe to hide flags that you add in custom list or document library without customization you can add the following code after the ContentPlaceHolder tage


<asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”>


The script as the following:


<script language="javascript" type="text/javascript">

// set the function that will load in the page call.


_spBodyOnLoadFunctionNames.push("hideFields");


//the function that will search for control


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]; }
}
}



// this function wil hide the controls by field Name



function hideFields()
{
var control = findacontrol("Hired");
control.parentNode.parentNode.style.display="none";
control = findacontrol("inServe");
control.parentNode.parentNode.style.display="none";
control = findacontrol("Title");
control.parentNode.parentNode.style.display="none";
}


</script>


you can change the Green text with your controls name that you need to hide

No comments: