I would like to limit the number of characters that can be typed into a textarea. Not just a simple character counter but one that has the ability to display a character count, warn the user of overstepping the limit(s) and actually limiting the total number of characters.
One of the best javascripts I’ve seen is ‘SpryValidationTextarea’ distributed freely by Adobe Labs at http://labs.adobe.com/technologies/spry/. It is part of a JavaScript library in their Spry framework for Ajax. Configurable in a number of modes with up or down character counter, minimum and maximum character limits and visual warnings for the user, etc.
The ‘SpryValidationTextarea’ script would be fabulous if it could be used in conjunction with FCKeditor or as a plugin. I’m very new to FCKeditor and also limited in my command of JavaScript. I’m willing to work at it if others can provide some help and guidance.
Here is what I’ve got so far. I tried to make the ‘SpryValidationTextarea’ limiter work in conjunction with FCKeditor rather than as a plugin due to my lack of knowledge of the plugin process. Maybe it would be better as a plugin??
To implement the SpryValidationTextarea widget before implementing FCKeditor:
---------------------------------
<head>
<!-- Link the JavaScript library to the textarea widget -->
<script src="lib/SpryValidationTextarea.js" type="text/javascript"></script>
<!-- Link the CSS style sheet to the textarea widget -->
<link href="lib/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
</head>
<body>
…
<span id="textarea_counter_up">
<textarea name="comments" id="comments" rows="5" style="width: 80%;"></textarea>
<span id="Counttextarea_counter"> </span>
<span class="textareaRequiredMsg">The value is required.</span>
<span class="textareaMaxCharsMsg">The maximum number of characters exceeded.</span>
</span>
<script type="text/javascript">
<!--
var textarea_counter_up = new Spry.Widget.ValidationTextarea("textarea_counter_up", {maxChars:30, counterType:"chars_remaining", counterId:"Counttextarea_counter", useCharacterMasking:true, validateOn:["change"]});
//-->
</script>
</body>
-----------------------------
The limiter script works correctly by itself, but if I now implement FCKeditor like this:
--------------------------------
<script type="text/javascript" src="FCKeditor/fckeditor.js"></script>
<script type="text/javascript">
window.onload = function()
{
var oFCKeditor = new FCKeditor( 'comments' ) ;
oFCKeditor.BasePath = "/FCKeditor/" ;
oFCKeditor.width = "80%" ;
oFCKeditor.height = 300 ;
oFCKeditor.ReplaceTextarea() ;
}
</script>
---------------------------------------------------
Now the ‘SpryValidationTextarea’ widget seems unable to access the form textarea. I’ve played with FCKeditor_OnComplete to call ‘SpryValidationTextarea’ after FCKeditor but I’m not knowledgeable enough about what needs to done to get inside FCKeditor.
Ideas, suggests, help? …
Doug
Mon, 05/14/2007 - 04:42
#1
RE: Character Max Length
There are several plugins, see this thread http://sourceforge.net/forum/forum.php? ... _id=257180
I assumed that they activilly constrained the total number of characters, but could you please confirm or deny this when you test them?