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
http://forums.asp.net/t/1166224.aspx
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…
RSS - Posts

[...] Read only field in SharePoint EditForm.aspx [...]
By: Links (2/1/2009) « Steve Pietrek - Everything SharePoint on February 1, 2009
at 11:56 pm
this was a great post. I have found it difficult to find a script that does not lose its value on post back, so now I am curious. How can this be applied to other field types like Select (lookup and dropdown). i have tried using the by ID, but not luck. Also tried to add multiple fields, but got an error.
By: larry on February 25, 2009
at 10:16 pm
Amazing !!!
Literally works
By: Ali Raza on April 24, 2009
at 2:12 pm
Nice post.
Thanks
For me its helps lot
regards
Jenkins
By: Jenkins on May 4, 2009
at 11:44 am
[...] Read only field in SharePoint EditForm.aspx Posted by Kit Filed in JavaScript, SharePoint Tags: Example, JavaScript, Prototype, SharePoint [...]
By: Kit Menke » Blog Archive » Make a Text field read only on EditForm.aspx without SPD on June 3, 2009
at 12:09 am
Great post, some of my customers have used this scripts to add collaboration content to LOB data in SharePoint lists with the help of the SharePoint Business Data List Connector.
Thanks again, Regards.
Frank
By: SharePointFrank on October 13, 2009
at 7:30 am
I didn’t know that Nishant Rana’s Weblog.
By: Tyre on November 10, 2009
at 7:20 am
I was just thinking about Nishant Rana’s Weblog and you’ve really helped out. Thanks!
By: Tyres on November 10, 2009
at 7:21 am