CKEditor insert HTML into textarea

12,395

Solution 1

This row:

CKEDITOR.instances.wysiwyg.insertHtml('[quote={$row['author']}]' + stringContent + '[/quote]');

the single quotes around 'author' are not escaped. Try:

CKEDITOR.instances.wysiwyg.insertHtml("[quote={$row['author']}]" + stringContent + "[/quote]");

Solution 2

This worked for me:

CKEDITOR.instances.TEXTATEA_ID.insertHtml('<p> html here. </p>');
Share:
12,395
bear
Author by

bear

Updated on June 04, 2022

Comments

  • bear
    bear almost 2 years

    I'm trying to insert text into CKEditor using javascript. I have currently got this script:

    function quote_<?php echo $row['pid']; ?>() {
            var stringContent = $(".content_<?php echo $row['pid']; ?>").html();
             $("#wysiwyg").val("[quote=<?php echo $row['author']; ?>]" + stringContent + "[/quote]");
             CKEDITOR.instances.wysiwyg.insertHtml('[quote=<?php echo $row['author']; ?>]' + stringContent + '[/quote]');
    }
    
    <textarea name="message" style="width:100%" tabindex="3" rows="10" id="wysiwyg">
    </textarea>
    

    HTML is not being inserted into the instance 'wysiwyg', so I can't get this to work.

    Any ideas?

  • Victor Nițu
    Victor Nițu about 12 years
    I can presume you already know all this, but you should be more careful about some shady syntax mixes, because javascript has the mighty power of silently failing, and that's exactly the point where you wouldn't know what happened actually ;-)
  • Vishnu
    Vishnu about 5 years
    Am facing the same issue Kindly look on this , stackoverflow.com/questions/55298230/…