Welcome to the OzoneAsylum FaqWiki
Frequently Asked Questions
DHTML/JavaScript

How do I create a JavaScript/DHTML rich text editor? Pages that link to <a href="https://ozoneasylum.com/backlink?for=5281" title="Pages that link to How do I create a JavaScript/DHTML rich text editor?" rel="nofollow" >How do I create a JavaScript/DHTML rich text editor?\

Giving the user the ability to add information via a textarea and actual format that text as they go along is a popular and powerful tool. Read the resources below for more information:

------------------------------
Relevant threads:

Html and textarea

I need help with textarea

------------------------------
Just a thought, if it can be IE only, have a look at the MS dhtml control. It's a very powerful scriptable html design engine (ie. you mark a text, click 'add link' (for example), then the script does a showModal() (IE only again), which displays a windowsy looking input window, and adds the link to the html control, where it is actually displayed as a link. I've even seen a table editor done with this.
--Tyberius Prime

Code example for the ms dhtml control:

code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>editablepageexample</title>
<script>
function b(){
document.execCommand("Bold", false, null);
}
function i(){
document.execCommand("Italic", false, null);
}
function r(){
document.execCommand("ForeColor", false, "red");
}
</script>
</head>
<body>

<div CONTENTEDITABLE="true">The text in this page is editable.<br></div>
<a href="javascript&#58;b();">bold</a>
<a href="javascript&#58;r();">red</a>
<a href="javascript&#58;i();">italic</a>
<br>
<br>
</body>
</html>



More info on commands can be found here:http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/commandids.asp

One way to do it is to make one page editable and show that in an iframe, you control the editing functions by buttons/images/links whatever, then on submit you grab the html from the page, strip out the head/body tags, place it in a hidden field that you submit, like this document.forms["your_submit_form_name"].your_hidden_field_name_here.value = window.frames['name_of_your_editor'].document.getElementById("name_of_the_editable_element").documentHTML

Takes some fiddling, but you can make it just about how advanced or simple you like.
//DmS
------------------------------
Relevant links:

Richtext editor

Rich Edit Component

Wysiwygger - an example produced by our own DmS.

Command Identifiers - useful information from the MSDN library.

----------------------------
Relevant note:

As of writing this FAQ is number 1 at Google in the search for the terms javascript, rich, text, editor and 6 for the terms rich, text, editor.

_______________________
Emperor

(Added by: Emperor on Sun 08-Sep-2002)

(Edited by: Tyberius Prime on Wed 11-Sep-2002)

(Edited by: Emperor on Thu 12-Dec-2002)

(Edited by: rey on Fri 20-Dec-2002)

(Edited by: DmS on Tue 14-Jan-2003)

(Edited by: deepak on Mon 28-Apr-2003)

(Edited by: Yvonne on Mon 28-Apr-2003)

(Edited by: simonmaz on Thu 12-Feb-2004)

(Edited by: lancefinal on Mon 15-Mar-2004)

« BackwardsOnwards »

Show Forum Drop Down Menu