Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
            }
        });
    }
like image 673
D-W Avatar asked Aug 26 '26 21:08

D-W


2 Answers

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() 
};
like image 177
Rory McCrossan Avatar answered Aug 29 '26 15:08

Rory McCrossan


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

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

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

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!