How to detect the textarea number of words?
I want to ckeck the textarea must enter at least 10 characters,
if not, will alert user and not submit.
<form action="index.php" method="POST" id="commform" name="commform" onsubmit="return checkdata(this);">
<TABLE CELLSPACING=1 CELLPADDING=2 BORDER=0 ALIGN="CENTER" WIDTH="100%">
<TR>
<TD class="coner6_back2" ALIGN="left">Comment :
<textarea name="fm_data[opinion]" id="opinion" cols="50" rows="20"></textarea>
<script language="JavaScript"><!--
CKEDITOR.replace('opinion', {
toolbar: 'MyBasic',
uiColor: '#FDBDBB'
});
//--></script></TD>
</TR>
<TR><TD ALIGN="CENTER">
<INPUT TYPE="SUBMIT" value="Submit">
</TD></TR>
</TABLE></FORM>
<script language="JavaScript"><!--
function checkdata(commform){
var element = CKEDITOR.document.getById('opinion');
if ( document.commform.opinion.value.length < 10 ) {
alert ('You must enter at least 10 characters!');
element.focus();
return false;
}
return true;
}
--></script>
But it does not work correctly.
submit first time, jump alert, even more than 10 words.
And can not focus to textarea.
Followed by second submit, it submitted (even fewer than 10 words).
