CKEditor and Javascript validation

I have been working with CKEditor recently and ran into an issue where I noticed some strange random behavior with regards to validation. I noticed that sometimes the validation would pass or fail unexpectedly. It turns out that it was due to the fact that the CKEditor instance creates a separate element for user input and hides the original text area which the validation code validates.  Since CKEditor doesn’t push the changes out to the text area until the control loses focus, if you click on the form submit button, the text area may or may not have been updated, so as a result, the validation may pass or fail unexpectedly.

The solution that I came up with was to add the following code to the form submit button before the form validation code. This ensures that the CKEditor content and the text area are always in sync when the validation runs.

//force each ckeditor instance on page to update their related text area elements so that we can perform validation on those elements 

if (CKEDITOR != undefined) {
   for (var instance in CKEDITOR.instances)

Hopes this helps someone that got stumped like I did. Smile