Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-13-2013, 12:00 PM   PM User | #1
howard-moore
Regular Coder

 
Join Date: May 2008
Posts: 114
Thanks: 13
Thanked 0 Times in 0 Posts
howard-moore is an unknown quantity at this point
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:

Code:
<script language="JavaScript" type="text/javascript">
 <!--
function checkform ( form )
 {
   if (form.title.value == "") {
     alert( "Please enter an article TITLE." );
     form.title.focus();
     return false ;
   }
   if (form.content.value == "") {
     alert( "Please check that you have entered an INTRODUCTION." );
     form.content.focus();
     return false ;
   }
   if (form.content2.value == "") {
     alert( "Please check that you have entered a FULL STORY." );
     form.content2.focus();
     return false ;
   }
   return true ;
 }
 //-->
 </script>
Many thanks,
Neil
howard-moore is offline   Reply With Quote
Old 02-13-2013, 04:52 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,035
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

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.

Last edited by Philip M; 02-13-2013 at 05:03 PM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:42 AM.


Advertisement
Log in to turn off these ads.