Friday, July 9, 2010

Make Read-Only fields in SharePoint List Forms using Javascript

Here is the code to make SharePoint list fields read-only like below screen:

Make Read-Only fields in SharePoint List Forms using Javascript

Here is the code to Make Read-Only fields in SharePoint List Forms using Javascript:
Open your list form (NewForm.aspx or EditForm.aspx) in SharePoint Designer, Paste the below code after: <asp:Content id="Content1" runat="Server" contentplaceholderid="PlaceHolderMain">

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("makeProjectIdReadOnly()");
function makeProjectIdReadOnly() {
document.getElementById('ctl00_PlaceHolderMain_g_f64398c9_7481_4633_ada6_b227977f9884_ff1_1_ctl00_ctl00_TextField').blur();
document.getElementById('ctl00_PlaceHolderMain_g_f64398c9_7481_4633_ada6_b227977f9884_ff1_1_ctl00_ctl00_TextField').readOnly=-1;

document.getElementById('ctl00_PlaceHolderMain_g_f64398c9_7481_4633_ada6_b227977f9884_ff1_1_ctl00_ctl00_TextField').className="Read-Only";
}
</script>
<style type="text/css">
.Read-Only {
BACKGROUND-COLOR: #f0f5f7
}
</style>



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

2 comments :

  1. I'm a noob, and i don't see this code to paste behind
    "Paste this code after: "


    ReplyDelete
    Replies
    1. Open the list form in SharePoint Designer!

      Delete

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...