The contenteditable attribute, available in HTML5 makes such editing easier. You can try it out yourself below:
- The text between the lines below is tagged with that attribute
- Feel free to edit it:
- Add line feeds (i.e., hit the Enter key)
- Highlight text and use CTRL B, or I or U
- The click the button to see the HTML text with your changes.
This text can be edited by the user. Feel free to edit it. You can even hit the enter key for a line feed. You might want to do this at the beginning of every sentence. You can also highlight some text and use CTRL-B, CTRL-I, CTRL-U to make the text bold or italic or underlined.
So how did I do that? All I had to do is wrap the text in a DIV tag with the contenteditable attribute enabled, i.e.,
<div contenteditable="true" id="cmnts">
The text I want the user to be able to edit.
The DIV tag has an ID attribute so I can get the HMTL text using the innerHTML attribute.
Now your next question, is how can I upload the value to the server since the text is not in a form field (e.g., an INPUT or TEXTAREA tag)? All I need to do is to create a hidden form field in my form, e.g.,
<input type="hidden" name="userText" id="userText">
and then in my form tag I add an onSubmit attribute to assign the HTML text to the form field, e.g.,
On the SAS Server side (e.g., the SAS/IntrNet® Application Dispatcher or the Stored Process Server), like for any other form field, a macro variable (userText) contains the HTML text that can be saved or used however the applications sees fit.
This is very much a Work In Progress and as I continue my research and experimentation with HTML5, hopefully I will find an easy to implement facility for a more complete Rich Text Editor. But for now, the contenteditable attribute is a pretty good alternative IMO.