I am using the Javascript version of FCKeditor and would like to limit the amount of text that can entered. Is there a configuration option to set the number of characters that can be entered in the editor, preferably minus the html markup (ie only count the displayed text)? Or if that option isn't available, can I get the length of the entered text when they click the submit button using javascript on the webpage, like you would with a regular html form?
Bill H
Bill H

Re: Limiting size
// Get the editor instance that we want to interact with and the document of the editor var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ; var oDOM = oEditor.EditorDocument ; // Get the editor contents in XHTML format and their length HTMLData.value = oEditor.GetXHTML( true ) ; HTMLDataLen.value = HTMLData.value.length ;This assumes you have two form fields (hidden is fine), one called HTMLData and the other called HTMLDataLen.
If you want the number of text characters (without formatting) then you can use something like this:
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' ) ; }Look at HTML Example 8 that ships with the download for more useful functions and information.
MD