Search code examples
javascriptjqueryajaxsceditor

Get the value from SCEditor


I'm trying to get the value from my SCEditor textarea, using this code:

var fbeschreibung = '';
$(function() {
    // Replace all textarea's
    // with SCEditor
    $("textarea").sceditor({
        plugins: "bbcode",
        style: "css/style.less",
        width: "100%",
        toolbar:"bold,italic,underline,strike,subscript,superscript|left,center,right,justify|size,color,removeformat|bulletlist,orderedlist,horizontalrule,emoticon",
        locale:"de" ,
        resizeEnabled:false
    });
    fbeschreibung = $('textarea').sceditor('instance').val();
    $('textarea').sceditor('instance').val('Hello [b]World![/b]');
});

I then want to send the value via AJAX:

$.post('saveprofile.php', 
   {fbeschreibung : fbeschreibung},
   function (response) {
      alert(response);
   }
);

However, I'm not able to get this to work. I haven't found find any tips in the documentation: http://www.sceditor.com/api/sceditor/val/

My variable fbeschreibung is just empty. Is there something I've done wrong?


Solution

  • This worked for me:

    $(function() {
        // Replace all textarea's
        // with SCEditor
        var fbeschreibung = $("textarea").sceditor({
            plugins: "bbcode",
            style: "css/style.less",
            width: "100%",
            toolbar:"bold,italic,underline,strike,subscript,superscript|left,center,right,justify|size,color,removeformat|bulletlist,orderedlist,horizontalrule,emoticon",
            locale:"de" ,
            resizeEnabled:false
        }).sceditor('instance');
        var value = fbeschreibung.getBody().html();
    });