Reputation: 11615
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?
Upvotes: 2
Views: 12937
Reputation: 345
This worked for me:
CKEDITOR.instances.TEXTATEA_ID.insertHtml('<p> html here. </p>');
Upvotes: 1
Reputation: 6255
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]");
Upvotes: 2
Reputation: 1505
You can always embed your javascript code into a .php file, as it follows:
<?php
echo <<<JS
<script type='text/javascript'>
function quote_{$row['pid']}() {
var stringContent = $(".content_{$row['pid']}").html();
$("#wysiwyg").val("[quote={$row['author']}]" + stringContent + "[/quote]");
CKEDITOR.instances.wysiwyg.insertHtml('[quote={$row['author']}]' + stringContent + '[/quote]');
}
</script>
<textarea name="message" style="width:100%" tabindex="3" rows="10" id="wysiwyg">
</textarea>
JS;
?>
Also, you can alternatively use php files in which you keep pure (X)HTML markup, but when you come to the point where you would normally echo, just do that:
var stringContent = $(".content_"+<?= $row['pid']; ?>).html();
Upvotes: 0