validating an FCKeditor text area

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

validating an FCKeditor text area

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you could prefill the field with the submitted article data.
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post 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!
Post Reply