Never thought that I could disallow user to edit a field in newform.aspx using simple javascript function. As soon as the page gets loaded i m finding the input box (need to disable a input field if you need to disable any other field change the params for getTagFromIdentifierAndTitle) and disabling it, so user cannot modify it. One can make use of the PreSaveAction function which is always called before request gets posted to server, where I am re-enabling the textbox.
Need to copy this Javascript function in newform.aspx with the help of Sharepoint designer in Placeholder main. Remember that I have a list with column name JSReadOnly so one will change it if they are having some other name. I havent tried but I hope it should also work field types other than TextField with little change.
function PreSaveAction()
{
var field = getTagFromIdentifierAndTitle("INPUT","TextField","JSReadOnly");
//alert(field.value);
field.disabled=false;
setTimeout('setFieldDisable()',1000);
return true;
}
function getTagFromIdentifierAndTitle(tagName, identifier, title) function setFieldDisable() setTimeout('setFieldDisable()',500);
{
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tempstring =" tags[i].id;" title ="=" identifier ="=">
{
var field1 = getTagFromIdentifierAndTitle("INPUT","TextField","JSReadOnly");
if(field1!=null)
field1.disabled=true;
else
setTimeout('setFieldDisable()',500);
}
Beware that there are pros and cons of SPD :)
