I try to use FCKeditor in our web application. But i don't know how to use count characters javascript in edit area. I want to limit the chars entered by user. Can anyone help me?
Sat, 10/22/2005 - 10:24
#1
RE: count characters on edit area
RE: count characters on edit area
var CharCountCommand = function (name)
{
this.Name = name;
}
CharCountCommand.prototype.Execute = function()
{
var oDOM = FCK.EditorDocument ;
var iLength ;
if ( FCKBrowserInfo.IsIE )
{
iLength = oDOM.body.innerText.length ;
}
else
{
var r = oDOM.createRange() ;
r.selectNodeContents( oDOM.body ) ;
iLength = r.toString().length ;
}
return iLength //number of characters
}
FCKCharCountCommand.prototype.GetState = function()
{
return FCK_TRISTATE_OFF;
}
Hope this is helpful.
jaco
RE: count characters on edit area
RE: count characters on edit area
editor_frame = document.getElementById(instanceName+'___Frame');
if (editor_frame!=null) {
editor_source = editor_frame.contentWindow.document.getElementById('eEditorArea');
if (editor_source!=null) {
oldcontent=editor_source.contentWindow.document.body.innerHTML;
if (oldcontent.length > maxlimit) {
editor_source.contentWindow.document.body.innerHTML=oldcontent.substring(0, maxlimit);
}
r = maxlimit - editor_source.contentWindow.document.body.innerHTML.length;
//if (r < 0) {
// alert("You have exceeded the word count, please decrease your words.");
//}
rem_field = 'document.page_fields.rem' + instanceName + '.value=\'Remaining: ' + r + ' characters\'' ;
//alert(rem_field);
eval(rem_field);
} else { return false; }
} else { return false; }
RE: count characters on edit area
In a javascript as a function I asume? And where do I have to set the maximum number of words?
Thx
RE: count characters on edit area