Page 1 of 1

validating an FCKeditor text area

Posted: Wed Feb 08, 2006 7:41 am
by Skittlewidth
Has anyone ever tried to validate an FCKeditor textfield before submitting a form?

I need to check the word count of a document in an FCK field before its submitted incase it exceeds the number of characters that will fit into a PDF template.

I tried just getting the value of the element id into a variable with Javascript and getting the length of the string but the value always seems to be empty.

Code: Select all

var mystring = document.getElementById('FCKeditor1').value;
var textlen = mystring.length;
I was originally checking the length serverside after the form had been submitted but the trouble is that if the length exceeds the maximum characters allowed, when the user clicks the back button or my back link, the form is completely empty and they're not going to be pleased at having to type the whole article again rather than just delete a few sentences.

Posted: Wed Feb 08, 2006 8:51 am
by feyd
you could prefill the field with the submitted article data.

Posted: Wed Feb 08, 2006 9:05 am
by Skittlewidth
Could you clarify?

I've just given a default value to FCK when it loads, to check that the javascript is correct, and that correctly returns a character length of 15, so there's obviously something about FCK that means I can't test that with unsubmitted data. It still returns 15 when I add to that default text.

Are you suggesting that I allow the form to submit, check the length serverside, and then post the values back to the form if it fails?

Posted: Wed Feb 08, 2006 9:23 am
by feyd
Skittlewidth wrote:Are you suggesting that I allow the form to submit, check the length serverside, and then post the values back to the form if it fails?
Yes.

The following is how the FCKeditor demo page prefills the field:

Code: Select all

<script type="text/javascript">
<!--
var oFCKeditor = new FCKeditor( 'FCKeditor1' ) ;
oFCKeditor.BasePath = '/fckeditor/' ;
oFCKeditor.Value = 'This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.' ;
oFCKeditor.Create() ;
//-->
</script>

Posted: Wed Feb 08, 2006 10:01 am
by Weirdan

Posted: Wed Feb 08, 2006 10:23 am
by Skittlewidth
Gah!!!... I've just finished doing it the long way! Oh well, I'll remember that link for next time. Thanks.

Edit: Infact I have decided to use it, to save a complicated and potentially buggy system from ever needing to be called.

I knew all I wanted was two lines of Javascript!