If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

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:

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 05: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.