Check FCKeditor

how FCKeditor can be checked for the required field using javascript.

+5
source share
4 answers

Try it,

var EditorInstance = FCKeditorAPI.GetInstance('message') ; 
if(EditorInstance.EditorDocument.body.innerText.length<=0)
{
alert("This firld is mandatory");
EditorInstance.EditorDocument.body.focus();
return false;
}

Source:

http://dreamtechworld.wordpress.com/2008/12/06/validating-firld-in-fckeditor-using-javascript/

+2
source

Use FireBug and see what hidden textareait updates. Then check this item.

if (document.getElementById('fckinstance').innerHTML === '') {
    alert('required field');
}

This is just an example. It probably doesn't use either id, because of multiple instances on the same page.

textareathat replaces FCKeditor is probably the one that contains its HTML.

Please note that FCKeditor may seem empty even though it has HTML in it.

+1
source

, FCKeditor , , , TEXTAREA:

function FCKCopy() {
    for (var i = 0; i < parent.frames.length; ++i ) {
        if (parent.frames[i].FCK)
            parent.frames[i].FCK.UpdateLinkedField();
    }
}

HTML TEXTAREA:

function stripHTML(oldString) {
    var matchTag = /<(?:.|\s)*?>/g;
    return $.trim(oldString.replace(matchTag, ""));
}

The above function uses the jQuery trim function. Use jQuery or replace it with some cropping function for java script, for example:

function trimIt(text) {
    rwhite = /\s/;

    trimLeft = /^\s+/;
    trimRight = /\s+$/;

    if ( !rwhite.test( "\xA0" ) ) {
        trimLeft = /^[\s\xA0]+/;
        trimRight = /[\s\xA0]+$/;
    }

    return text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
}

Now you can check the TEXTAREA value, for example, as shown below:

if (stripHTML($('message').val()) == '') {
     alert('Please enter Message.');
}

I hope it works as well as it does for me.

Good luck

+1
source

it may be useful for someone

var EditorInstance = FCKeditorAPI.GetInstance('JobShortDescription');

alert(EditorInstance.GetHTML());

resource http://docs.cksource.com/FCKeditor_2.x/Developers_Guide/JavaScript_API

0
source

All Articles