Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2008
    Thanked 0 Times in 0 Posts

    CKEditor textarea validation problem

    Hi All,

    I have tried putting this to the CKEditor forum but they appear to blank it, so am coming here in desperation.

    I use the following script to validate whether someone has added any content to a text area, which also uses the popular, open-source text editor, CKEditor. Without CKEditor it works absolutely fine, but when I use it, it does not recognise the text that has been added until the second click, and so displays the warning message even if text has been added to the textbox.

    I have done lots of research on this but cannot understand any of the work-arounds. Can anyone offer any suggestions? My script is:

    <script language="JavaScript" type="text/javascript">
    function checkform ( form )
       if (form.title.value == "") {
         alert( "Please enter an article TITLE." );
         return false ;
       if (form.content.value == "") {
         alert( "Please check that you have entered an INTRODUCTION." );
         return false ;
       if (form.content2.value == "") {
         alert( "Please check that you have entered a FULL STORY." );
         return false ;
       return true ;
    Many thanks,

  2. #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,700 Times in 2,676 Posts
    If you use this forum you ought by now to be aware of:-

    a) <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead (in fact also deprecated but still necessary for IE<9).
    The <!-- and //--> comment (hiding) tags have not been necessary since IE3 (i.e. since September 1997). If you see these in some published script it is a warning that you are looking at ancient and perhaps unreliable code.

    b) alerts are considered to be obsolete and only useful for testing purposes. You should use DOM methods to display your messages to the user. You might wish to check for and reject dodgy characters such as []#|!"'$%&\/()=^<>*+ which are unlikley to appear in a title.

    c) Form validation of the pattern if (document.formname.formfield.value == "") - that is blank - is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. A proper name may only contain letters, hyphen, space and apostrophe.
    Numeric values, such as zip codes, phone numbers and dates, should be validated as such. Ditto email addresses. This topic has been covered many times before in this forum.

    I would have thought that as a minimum you ought to strip leading/trailing/multiple spaces from the fields, and set a minimum length for the text.

    Apart from those issues I don't see anything wrong with your code. But I know nothing of CKEditor.You mention work-arounds so presumably this problem is endemic.

    Quizmaster: What is the English translation of the French word voiture?
    Contestant: A tree.
    Last edited by Philip M; 02-13-2013 at 06:03 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


Posting Permissions

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