SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Displaying the number of characters typed in FCKeditor

    Hello all,

    Is there a way I can count the number of characters typed on the FCKeditor so that I can restrict
    any input from exceeding the maximum characters allowed?

    On the form containing the FCKeditor, I would also like to display the number of characters being
    typed so that the users know how many characters are remaining.

    Thank you

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Textfields have the attribute maxlength, but textareas don't. You can always find out how many charachters are entered by
    Code:
    var iLength = document.forms["myForm"].myTextarea.value.length;

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used the following code to calculate the number of characters typed on the FCK editor. This works in IE but when I try to do the same in Mozilla, it shows no effect.

    Code:
    <html>
    <head>
    <script language="javascript">	
    function onchangeListener() 
    { 
    	var api=FCKeditorAPI.GetInstance("txtProfile");
    	var html = api.GetXHTML(); 
    	var plain_text = RemoveHTML(html); 
    	
    	 document.getElementById('testDiv').innerHTML =5000-plain_text.length; 
    }
     
    function RemoveHTML( strText ) 
    { 
    	var regEx = /<[^>]*>/g; 
    	return strText.replace(regEx, ""); 
    } 
     
    setTimeout('delayHook();',1000); 
    function delayHook() 
    { 
       FCKeditorAPI.GetInstance("txtProfile").EditorDocument.attachEvent( "onkeyup",onchangeListener); 
    } 
     
    
    </script>
    <body>
    <script language="javascript" src="/FCKeditor/fckeditor.js"></script>
    </head>
    <script type="text/javascript">
    var oFCKeditor = new FCKeditor('txtProfile');
    oFCKeditor.BasePath = "/FCKeditor/";
    oFCKeditor.Width = "400";
    oFCKeditor.Height = "300";
    oFCKeditor.ToolbarSet	= 'Basic' ;
    oFCKeditor.Create();
    </script>
    
    
    <div id="testDiv" style="font-weight:bold;">5000</div> characters remaining
    </body>
    </html>
    How can I display the character count independent of what browser I am currently working with?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •