In order to create a clean read only output for the user in multiple browsers the following needs to be performed:
- Hide the textarea, shown by non IE browsers. This textarea could simply be disabled and left visible but it contains HTML tags generated during rich text edit, not clean output.
- Hide the Rich Text Editor toolbar, shown within IE.
- Hide the Rich Text Editor window, shown within IE.
- Hide the link shown within non IE browsers that describes entry of basic HTML formatting.
- If required hide the text description of the output, you may not wish to show the description of entry field.
- Add the output of the textarea in place of all the above elements.
It's important that the elements are hidden rather than removed as they will be required upon form submission.
The following function takes the title of a textarea and will achieve all of the above steps. It can be modified as necessary to leave descriptions etc.
function DisableTextArea(title) {
// Hide the textarea and get it's content, note that the content comes formatted with HTML tags.
var newOutput = $("textarea[title='"+ title +"']").hide().val();
// Add text area content to the parent tag for the area. This provides a read only output of the text area.
$("textarea[Title='"+ title +"']").closest("span").append( newOutput );
// Hide the rich text editor toolbar.
$("textarea[Title='"+ title +"']").closest("span").find("table[id$='_toolbar']").hide();
// Hide the rich text editor window.
$("textarea[Title='"+ title +"']").closest("span").find("iframe[title='Rich Text Editor']").hide();
// Hide the link to HTML editing info, visible within non IE browser.
$("textarea[Title='"+ title +"']").closest("span").parent("span").find("span.ms-formdescription").hide();
// Hide any text within the parent div, as entry isn't allowed we don't need the text describing input.
$("textarea[Title='"+ title +"']").closest("td").contents().filter(function(){
return(this.nodeType == 3);
}).remove();
}