Different ways to make column or Field Readonly in SharePoint 2013/2016/Online list

This SharePoint tutorial, we will discuss how to make a field or a column of a SharePoint list as ReadOnly. You might encounter a situation where you need to make a column as read-only when the user trying to submit an item or edit an item in SharePoint 2013/2016 or SharePoint Online.

There are different ways you can make a SharePoint list column as read-only.

Make SharePoint list field read-only using JavaScript

To use JavaScript code to make the SharePoint list field as read-only, just edit the page and then put the below code inside a Script editor webpart.

<script type="text/javascript">
function SetReadOnlycolumn()
{
var elements=document.getElementById(‘Your column name in the view source’);
elements.readOnly=true;
}
_spBodyOnLoadFunctionNames.push("SetReadOnlycolumn()");
</script>

Make SharePoint list field read-only using SPUtility.js

SPUtility.js is a JavaScript library that you can download from GitHub and use it in your SharePoint 2016/2013/2010 or MOSS 2007 site. This also works in SharePoint Online. By using this SharePoint library we can modify list forms like NewForm.aspx and EditForm.aspx.

Edit your page and put the below code inside a script editor web part. Make sure to give reference to sputility.min.js which we have downloaded from GitHub.

<script type="text/javascript">
function MakeFieldReadOnly()
{
SPUtility.GetSPField(‘Name of your List Field’).MakeReadOnly();

}
_spBodyOnLoadFunctionNames.push("MakeFieldReadOnly");
</script>

Make SharePoint list field read-only using SharePoint Server Object Model Code

We can hide a SharePoint list column by using the Server-side object model code in SharePoint 2013/2016. Below is the code sample to make the SharePoint list field read-only.

SPList list = web.Lists["List Name"];
SPField myField = list.Fields["Name of your List Field"];
myField.ReadOnlyField = true;
myField.Update();

You may like following SharePoint tutorials:

This SharePoint tutorial, we learned various ways to make a column or field read-only in the SharePoint list using JavaScript, SPUtility.js and using the SharePoint server object model.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>