| |
Database Integration
When the HTML Rich Text Area is integrated with a database special consideration needs to
be given to the relationship between the raw data and javascript.
Your server side technology (ASP, Perl, ASP.NET, etc) will need to generate the following
code to be sent to the browser:
<SCRIPT
LANGUAGE="javascript" SRC="../inc/HTMLRichTextArea.js"></SCRIPT> <SCRIPT LANGUAGE="javascript" SRC="../inc/HTMLRichTextAreaFactorySettings.js"></SCRIPT> <SCRIPT LANGUAGE="javascript"> <!-- var strDefaultHTML = "[TEXT FROM DB GOES HERE]"; new
HTMLRichTextArea("content", 80, 200,
strDefaultHTML).Draw(); //--> </SCRIPT>
If you simply insert the text from the database straight into [TEXT FROM DB GOES HERE] then
any number of problems could cause a javascript syntax error. For example, the text from the database
may be:
This will generate the javascript code:
This will throw a javascript error because the javascript string is terminated at the double-quote at the
beginning of 'Smith' and everything after this is unexpected. If it weren't this then the other double quote,
the carriage return and line feed or backslash would also cause problems.
To solve these issues some preprocessing needs to be performed before the string is inserted into
the HTML Rich Text Area. The following characters need to be escaped by preceding them with a backslash
- quote (')
- double quote (")
- backslash (\)
and a carriage return and line feed needs to be escaped by replacing it with a '\n';
For example the above processing would create:
The ASP code needed to do this is listed below. This code can be readily modified for any other
server side technology:
To call this function you would use code like:
If you are using ASP then all of this code has been provided for you in the /inc/HTMLRichTextArea.asp
file. Read the section on ASP for more information.
|
|