Hi,
I want to dynamically count number of symbols (with HTML tags) I've entered into FCKeditor area. I.e. bellow the editor I want to see number of symbols I get after submitting a form. How to design this?
The code is:
<script type="text/javascript" src="http://my-trunk.odesk.local/htdocs/js/F ... keditor.js"></script>
<script type="text/javascript">
var oFCKeditor = new FCKeditor('EditorName');
oFCKeditor.BasePath = "http://my-trunk.odesk.local/htdocs/js/FCKeditor/";
oFCKeditor.InstanceName = "EditorName";
oFCKeditor.Value = "<p>Some<br /> value</p>";
oFCKeditor.Width = "705px";
oFCKeditor.Height = "300px";
oFCKeditor.ToolbarSet = "Basic";
oFCKeditor.Config["FormatOutput"] = "false";
oFCKeditor.Config["UseBROnCarriageReturn"] = "false";
oFCKeditor.Create();
</script>
<table id="TABLE_14" border="0" width="600">
<tbody><tr>
<td align="left" width="500">
<span id="EditorName_divchar"><span style="white-space: normal; color: rgb(112, 112, 112); font-size: 11px;">Char count: 0 (2,000 char limit)</span></span>
</td>
</tr>
</tbody></table>
<script>
function FCKeditor_OnComplete( editorInstance )
{
if (document.all) { // If Internet Explorer.
editorInstance.EditorDocument.attachEvent("onkeydown", set_char_count) ;
} else { // If Gecko.
editorInstance.EditorDocument.addEventListener( 'keypress', set_char_count, true ) ;
}
set_char_count();
}
function set_char_count()
{
var cnt=0;
var oEditor = FCKeditorAPI.GetInstance('EditorName') ;
cnt = oEditor.EditorDocument.body.innerHTML.length;
// cnt = oEditor.GetXHTML().length;
document.getElementById( "EditorName_divchar").innerHTML = '<span style="white-space: normal; color: #707070; font-size: 11px;">Char count: ' + cnt + ' (2000 char limit)</span>';
}
</script>
*******************
So. I have there two ways of counting of cnt (ONLY FOR IE):
- oEditor.EditorDocument.body.innerHTML.length;
- oEditor.GetXHTML().length;
When I use the first way I receive HTML which is not the same I get after Submit.
When I use the second way, I receive a needed HTML, BUT after this action I can't enter to FCKEtitor a couple of Spaces or make a new line (<br /> is NOT inserted) AT THE END of my text. In the middne of the text all works fine.
*******************
Please tell how to count number of symbols entered to the Editor (in IE!!!) with tags dynamically?
At every key press I want to see number of symbols I will see in Source area if I click 'Source' button.
Mon, 06/04/2007 - 02:20
#1
RE: Count number of symbols with HTML tags