Hi,
I'd like to use FCKeditor for text input in a form, but limit the amount of characters (real characters, not counting HTML tags) that the user is allowed. Does anyone have any brilliant ideas? Many thanks in advance.
I'd like to use FCKeditor for text input in a form, but limit the amount of characters (real characters, not counting HTML tags) that the user is allowed. Does anyone have any brilliant ideas? Many thanks in advance.
RE: Character counter with FCKeditor
RE: Character counter with FCKeditor
mystring = oEditor1.GetXHTML(null).replace(/<[^>]*>/g, '');
Then you'll need another few to remove the nbsps and so forth.
RE: Character counter with FCKeditor
You can see how it works and try to pour it into a plugin that 'undoes' the last typing action or -even better- that cancels this action from having affect (placing the typed character)
function GetLength()
{
// This functions shows that you can interact directly with the editor area
// DOM. In this way you have the freedom to do anything you want with it.
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
// Get the Editor Area DOM (Document object).
var oDOM = oEditor.EditorDocument ;
var iLength ;
// The are two diffent ways to get the text (without HTML markups).
// It is browser specific.
if ( document.all ) // If Internet Explorer.
{
iLength = oDOM.body.innerText.length ;
}
else // If Gecko.
{
var r = oDOM.createRange() ;
r.selectNodeContents( oDOM.body ) ;
iLength = r.toString().length ;
}
alert( 'Actual text length (without HTML markups): ' + iLength + ' characters' ) ;
}