How to show ID field as readonly in Edit Form, of a sharepoint list?

Guilherme de Jesus Santos picture Guilherme de Jesus Santos · Jul 21, 2010 · Viewed 7.5k times · Source

I need to show the ID field in the Edit Form of a sharepoint list.

There is a way to do it ? I tried a calculated field and nothing. I know that I can see the ID field in the view, and if I show as a Access Mode. I'm using WSS3.0

Answer

Ryan picture Ryan · Jul 26, 2010

You can add the ID field to the form using some JavaScript in a CEWP.

<script type="text/javascript"
   src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script type="text/javascript">

$(function() {
  // Get the ID from the query string
  var id = getQueryString()["ID"];

  // Find the form's main table
  var table = $('table.ms-formtable');

  // Add a row with the ID in
  table.prepend("<tr><td class='ms-formlabel'><h3 class='ms-standardheader'>ID</h3></td>" +
                "<td class='ms-formbody'>" + id + "&nbsp;</td></tr>");
})

function getQueryString() {
  var assoc = new Array();
  var queryString = unescape(location.search.substring(1));
  var keyValues = queryString.split('&');
  for (var i in keyValues) {
    var key = keyValues[i].split('=');
    assoc[key[0]] = key[1];
    }
  return assoc;
}
</script>

There is an alternative method that doesn't use the jQuery library if you prefer to keep things lightweight.