I know this has been asked before, but the anwer doesn't seem to work for the latest version 2.0 RC3. How can I get the value of the editor to verify the user has entered in information via Javascript?
That seems really complicated, it seemed like all that was needed was to make sure the editor isn't blank.
//test if the value is empty function isEmpty(s){ if(s==null || s.length==0){ return true; } else return false; }
//test if the value only contains whitespace function isWhiteSpace(s){
var whiteSpace ="\t\n\r "; var i; if (isEmpty(s))return true; for(i=0;i<s.length;i++){ var c = s.charAt(i); if(whiteSpace.indexOf(c)==-1)return false; } return true;
}
function validateEditor(){ var oFCKeditor = FCKeditorAPI.GetInstance('body'); var myText = oFCKeditor.GetXHTML(false);
if(isWhiteSpace(myText) || myText == " "){ alert("You must enter a value into the editor!"); return false; } else{ return true; } }
Wow!! Thanks for all the replies... I still didn't get a chance to try this last night, but I will ensure I do so tonight! It makes sense the code and I think it will work!
RE: Check for Variable
a) a completely empty value
b) a value with only whitespace characters (\n\t\r)
c) a value with only an html space in it ( )
Set it to return true if any of those three are true, otherwise return false.
Then write another function to create your instance and grab the value.
var oFCKeditor = FCKeditorAPI.GetInstance('InstanceName');
var myText = oFCKeditor.GetXHTML( false );
Then pass in the value of MyText into the whiteSpace function. Easy!
RE: Check for Variable
Thanks!
Dave
RE: Check for Variable
RE: Check for Variable
FCKEditor puts the contents in the input given in parameter when the form is submited. So the form must be submited in order to verify the data.
Note that here, the FCK input is called "szContenu_PM", and the form is called "formulaire".
The javascript code is :
function Verif()
{
var Form = document.formulaire;
Form.target = '_self';
Form.action = 'Javascript:Valider();';
Form.submit();
}
function Valider()
{
var bError,szError;
var Form = document.formulaire;
bError = false;
szError = '';
if(!Form.szContenu_PM.value || Form.szContenu_PM.value==' ')
{
bError = true;
szError = szError + 'return the error code here....';
}
if(bError == true)
{
Form.target = '_self';
Form.action='Javascript:Verif(document.formulaire);';
alert(szError);
}
else
{
Form.target = '_self';
Form.action='my_script.php';
Form.submit();
}
}
The first call is in the "Verif" function, for example : <a href='javascript:Verif(this.formulaire);'>Valider</a>
RE: Check for Variable
//test if the value is empty
function isEmpty(s){
if(s==null || s.length==0){
return true;
}
else return false;
}
//test if the value only contains whitespace
function isWhiteSpace(s){
var whiteSpace ="\t\n\r ";
var i;
if (isEmpty(s))return true;
for(i=0;i<s.length;i++){
var c = s.charAt(i);
if(whiteSpace.indexOf(c)==-1)return false;
}
return true;
}
function validateEditor(){
var oFCKeditor = FCKeditorAPI.GetInstance('body');
var myText = oFCKeditor.GetXHTML(false);
if(isWhiteSpace(myText) || myText == " "){
alert("You must enter a value into the editor!");
return false;
} else{
return true;
}
}
RE: Check for Variable
Thanks again!
Dave
RE: Check for Variable
Thanks!
Dave