Hi all I am very new to javascript and jquery so bear with me, I am trying to make a multi-quote system for my sites comments system. SCEditor is this btw: http://www.sceditor.com/
I have this code
<script>
function insert_quote(quote_id)
{
var text = Document.getElementById(quote_id).innerHTML;
$('textarea').sceditor('instance').insert(text);
}
</script>
And this:
<td valign="top">
<div id="{:comment_id}" class="forumpost">{:text}</div><br />
<a onclick="insert_quote({:comment_id});">Multi Quote Test</a>
</td>
Where {:comment_id} would be the id of the comment from the database.
It doesn't work since i'm obviously doing something stupidly wrong, can someone help?
First you didn't put quote to (quote_id)
and document
have not uppercase so it is why it doesn't work. But it would be preferable do to all by jQuery and remove the "onclick" attribute like this.
JS
$('.comment').on('click', function() {
var text = $(this).prev('.forumpost').text();
$('textarea').sceditor('instance').insert(text);
});
HTML
<td valign="top">
<div id="{:comment_id}" class="forumpost">{:text}</div><br />
<a class="comment">Multi Quote Test</a>
</td>
EDIT
Here's a jsFiddle to see it in action.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.