web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Nishant Rana’s Weblog / Read only field in SharePoi...

Read only field in SharePoint EditForm.aspx

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee
Using JavaScript
First find out the tag corresponding to the input field which would like to set as read only
For this open up the editform.aspx page right click it and select view source
Say this is the tag of the input field
<input name=”TextField” type=”text” value=”Approved” maxlength=”255″ id=”4_ctl00_ctl00_TextField” title=”Status of Idea” class=”ms-long” />
Now open your editform.aspx page in SharePoint designer and add the following script to it
<script type=”text/javascript”>
function SetReadOnly()
{
// find all the elements with tag Name as INPUT
var elements=document.body.getElementsByTagName(“INPUT”);
// loop through all the elements till we find an element with type text and title as name of our field
for (index=0; index < elements.length;++index)
{
if(elements[index].type==“text”)
{
if(elements[index].title==“Status of Idea”)
{
elements[index].readOnly=true;
}
}
}
}
_spBodyOnLoadFunctionNames.push(“SetReadOnly()”);
</script>
Or
<script type=”text/javascript”>
function SetReadOnly()
{
var elements=document.getElementById(‘4_ctl00_ctl00_TextField’);
elements.readOnly=true;
}
_spBodyOnLoadFunctionNames.push(“SetReadOnly()”);
</script>
Or using event handler as mentioned over here
Or
Using CAML
And to hide button say OK button than
function SetHidden()
{
alert(‘Hi’);
var x=document.getElementsByTagName(“input”);
for (var i=0;i<x.length;i++)
{
if (x.item(i).type==”button”&&x.item(i).value==”OK”)
{
x.item(i).style.display = “none”
};
}
}
_spBodyOnLoadFunctionNames.push(“SetHidden()”);

Bye…

Posted in SharePoint Tagged: SharePoint

This was originally posted here.

Comments

*This post is locked for comments