I want to use a javascript (codethateditor) to provide a rich text editor in an administrative area of a site.

Problem with this script. See code below:

<script language="javascript1.2">
<!--
var editorDef = {
	text : '#get_text.text_content#',
	style : {
		width : 400,
		height : 400,
		defaultClass : {
			backgroundcolor : "##ffffff",
			bordercolor : "##efefe0",
			borderstyle : "inset",
			borderwidth : 2
		}
	}
};
var editor = new CEditor('sample', editorDef);
editor.create(); 
//-->
</script>

The site is written in Coldfusion. The javascript variable text is equal to the Coldfusion variable #get_text.text_content# (get_text is the name of the query and text_content is a column returned from a table).

When text_content contains html tags like

<h1>hello world</h1>

[continued] ... my javascript editor breaks. I get a javascript error at the bottom of the page. Neither the editor nor its contents are visible.

What can I do to allow the editor to start off with the value that is stored in the database?

Galaxygal

First thing to try is to store escape(text) rather than text . Then use unescape('#get_text.text_content#') to restore. This may work for you.

For what it's worth, there are other ways of "tokenising" tags (and bbCode). Forum/content management systems are quite sophisticated in this regard. I am not greatly experienced but once had to dabble in this area in phpBB for some reason (to add a new bbCode tag I think). I recall quite extensive (and impenetrable) use of regular expressions.

You could do worse than download open source suite (phpBB, vBulletin, Joomla or Drupal) and see how they do it, though be aware that they all do this stuff server-side, not client-side, so you would need to adapt.

Airshow

In one of my many atttempts, I did try the escape thing without any success. I moved on to a different editor and ran into the same problem.

I took a guess that replacing #chr(10)# and #chr(13)# and #chr(09)# might work (line returns and tabs). That did it for the new editor. I am guessing that approach would have worked with the codethateditor as well. I may go back and try it when I'm not half crazed -- stayed with this problem for the last 6 hours until I got it resolved because I'm extremely stubborn and have a Mac user who really really wants the benefit of a rich text editor right away.

Cheers,

galaxygal

Also remember that 'single quotes' need to be encoded or escaped because you retreive your text into a single-quoted string. But you're probably doing this already.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.