Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6957009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:56:38+00:00 2026-05-27T14:56:38+00:00

I realize I am probably doing this completely wrong, but here is my issue…

  • 0

I realize I am probably doing this completely wrong, but here is my issue…

I am using jQuery to grab a populated form (for editing content) using ajax. This form has a textarea that I am replacing with CKEditor. The thing that starts this is when you select the entry you want to edit through a drop-down list. It then pulls the appropriate information from the database and populates the form, which is sent back and my code puts into a div.

I first had the form on the static page with the jQuery+ajax pulling the data to populate the fields. But this would not update the CKEditor with the textarea content. So then I made the ajax return the entire form instead of just the data, and my jQuery put the form onto the page. This works the first time you select something to edit, but if you then change what you are editing, the CKEditor does not replace the textarea, and I get a javascript error saying:

i.contentWindow is null

in my ckeditor.js file.

Here is my script (the reason there are so many commented out parts is because I tried a lot of things to get this to work…):

<script type="text/javascript">
//$(document).ready(textEditor());
$("select#news").change(function(){
    if ($(this).val() != "NULL"){
        $.ajax({
            url: "/?r=Content_News_Edit",
            global: false,
            type: "POST",
            data: {news_id : $("option:selected",this).attr('value')},
            dataType: "html",
            async:false,
            success: function(data){
                $("div#fillContent").html(data);
            /*  //create jquery object from the response html
                var $response=$(data);

                //query the jq object for the values
                $("input#news_id").val($response.filter("div#news_id").text());
                $("input#news_heading").val($response.filter("div#news_heading").text());
                $("input#news_body").text($response.filter("div#news_body").text());
            */  
                textEditor();
            }
        });
    }
});

function textEditor(){
    var instance = CKEDITOR.instances['news_body'];
    if(instance){
        instance.destroy();
    }
    instance = null;

    CKEDITOR.replace( 'news_body',{
        height              : "600",
        width               : "550",
        filebrowserBrowseUrl        : '<?=$system['resource']?>/ckeditor/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/ckfinder.html?Type=Flash',
        filebrowserUploadUrl        : '<?=$system['resource']?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
        filebrowserImageUploadUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
    });
};
</script>

Help is greatly appreciated.

SOLVED

Finally figured it out. Here is my code:

<script type="text/javascript">
$("select#news").change(function(){
    if ($(this).val() != "NULL"){
        $.ajax({
            url: "/?r=Content_News_Edit",
            global: false,
            type: "POST",
            data: {news_id : $("option:selected",this).attr('value')},
            dataType: "html",
            async:false,
            success: function(data){
                //create jquery object from the response html
                var $response=$(data);

                //query the jq object for the values
                $("input#news_id").val($response.filter("div#news_id").text());
                $("input#news_heading").val($response.filter("div#news_heading").text());
                $("input#news_body").text($response.filter("div#news_body").text());

                var instance = CKEDITOR.instances['news_body'];
                instance.setData($response.filter("div#news_body").text())
            }
        });
    }
});

CKEDITOR.replace( 'news_body',{
    height              : "600",
    width               : "550",
    filebrowserBrowseUrl        : '<?=$system['resource']?>/ckeditor/ckfinder/ckfinder.html',
    filebrowserImageBrowseUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/ckfinder.html?Type=Images',
    filebrowserFlashBrowseUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/ckfinder.html?Type=Flash',
    filebrowserUploadUrl        : '<?=$system['resource']?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
    filebrowserImageUploadUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
    filebrowserFlashUploadUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
});
</script>

I moved the form back to the page that called the ajax method and and replaced the textarea with the CKEditor right away. Then, the ajax runs, and I put the CKEditor instance into a variable. I HAD to do this, or else I would get an error saying “CKEDITOR.instances.news_body is not defined.” Anyway, then I just used the variable to set the data within the CKEditor instance. Data changes work fine, and saves to the database fine. Hope this helps someone else.

Also, I found this answer mostly accurate at How to add data to CKEditor using JQuery by @PanJanek, and voted his answer up, because the original author answered his own question 2 hours later with PanJanek’s answer, with an added “F5″… -.-

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:56:38+00:00Added an answer on May 27, 2026 at 2:56 pm

    (Placing the answer here so this can be closed.)

    Finally figured it out. Here is my code:

    <script type="text/javascript">
    $("select#news").change(function(){
        if ($(this).val() != "NULL"){
            $.ajax({
                url: "/?r=Content_News_Edit",
                global: false,
                type: "POST",
                data: {news_id : $("option:selected",this).attr('value')},
                dataType: "html",
                async:false,
                success: function(data){
                    //create jquery object from the response html
                    var $response=$(data);
    
                    //query the jq object for the values
                    $("input#news_id").val($response.filter("div#news_id").text());
                    $("input#news_heading").val($response.filter("div#news_heading").text());
                    $("input#news_body").text($response.filter("div#news_body").text());
    
                    var instance = CKEDITOR.instances['news_body'];
                    instance.setData($response.filter("div#news_body").text())
                }
            });
        }
    });
    
    CKEDITOR.replace( 'news_body',{
        height              : "600",
        width               : "550",
        filebrowserBrowseUrl        : '<?=$system['resource']?>/ckeditor/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/ckfinder.html?Type=Flash',
        filebrowserUploadUrl        : '<?=$system['resource']?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
        filebrowserImageUploadUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl   : '<?=$system['resource']?>/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
    });
    </script>
    

    I moved the form back to the page that called the ajax method and and replaced the textarea with the CKEditor right away. Then, the ajax runs, and I put the CKEditor instance into a variable. I HAD to do this, or else I would get an error saying “CKEDITOR.instances.news_body is not defined.” Anyway, then I just used the variable to set the data within the CKEditor instance. Data changes work fine, and saves to the database fine. Hope this helps someone else.

    Also, I found this answer mostly accurate at How to add data to CKEditor using JQuery by @PanJanek, and voted his answer up, because the original author answered his own question 2 hours later with PanJanek’s answer, with an added “F5″… -.-

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize this is probably a hopelessly newbie question, but what is the difference
I realize it's probably something strange, but here is what I have. I have
I realize that this would be COMPLETELY bad practice in normal situations, but this
I realize what I'm doing is probably pretty silly, but I'm in the middle
I realize I'm probably just dumb and missing something big and important, but I
I realize there is a somewhat related thread on this here: Loading assemblies and
I realize this would violate convention, but I'm curious to know if you can
This isn't a school assignment or anything, but I realize it's a mostly academic
I realize that this question is impossible to answer absolutely, but I'm only after
I am sure this is probably something simple that i am not doing. Running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.