When we need to make some fields as read only when users wants to edit the item.This thing we can do very easily by SharePoint Designer , open that edit form and create one custom form and edit the field in which we want to make as read only we can change displaymode as edit. But what if do not want to change by SharePoint Designer.
We have very easy way which named as “JavaScript”.
I need to make one field as read-only, here is sample code
Open the editform.aspx page for a list and add one “Content Editor Webpart”, add the below javascript code.
<script type="text/javascript">
function MakeReadOnly()
{
// 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=="Address") //Field name
{
elements[index].readOnly=true;
}
}
}
}
_spBodyOnLoadFunctionNames.push("MakeReadOnly()");</script>
Hope this helps!!!
Disha Shah