D-W
D-W

Reputation: 5341

Ckeditor value and Jquery

I dont seem to be able to get the value from my ckeditior, any ideas where im going wrong?

<textarea  class="ckeditor" id="Source"></textarea> 
<a href="javascript:void(0);" onclick="SendPreview()" class="pOrange"> Send</a>
function SendPreview() {
        var value = CKEDITOR.instances['Source'].getData();
        var model = { EmailBody: Source, EmailTo: "[email protected]", EmailSubject: $(".Subject").val() };
        var request = $.ajax({
            url: '/Campaign/SendPreviewEmail',
            type: 'POST',
            dataType: 'JSON',
            data: { model: JSON.stringify(model) },
            cache: false,
            success: function (data) {
                var dataAsString = JSON.stringify(data);
            }
        });
    }

Upvotes: 2

Views: 14269

Answers (2)

user2724283
user2724283

Reputation:

Check the below, This may help you to get your solution

var value = CKEDITOR.instances['Source'].getData();

    //or
    $('#Source').ckeditor(function( textarea ){
      $(textarea).val();
    });

Upvotes: 2

Rory McCrossan
Rory McCrossan

Reputation: 337560

What you have works, the problem is because you're setting the value of the CKEditor to the value variable, but using Source in your model. Try this:

var value = CKEDITOR.instances['Source'].getData();
var model = { 
    EmailBody: value, // <-- Change this
    EmailTo: "[email protected]",
    EmailSubject: $(".Subject").val() 
};

Upvotes: 8

Related Questions