MyBB Community Forums

Full Version: Using javascript to insert text into the editor?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've developed a piece of JS which, when a button is pressed, appends some text into the Quick Reply textarea, like this:

function pastetext() {
result = "This text is pasted in the textarea!";
document.getElementById("message").value += result;
}
<div style="margin: 0 auto; text-align:center;"><input type="button" name="submit" onclick="pastetext()" value="Add text to post"></div>

However I cannot, for the life of me, figure out how to do the same thing on the main "New Reply" page, with the default myBB editor.

I'm aware that the above is not recommended, and I should be using jquery instead - I think I also may have found a jquery solution for what I'm trying to do - I did attempt to just stick this in, but clearly I don't know what I'm doing with jquery  Confused

I'll start working on learning to use jquery now, but is there a non-jquery solution to what I want to do?
Or if not, could anyone rewrite the short function & trigger above using jquery so I can work off an example?

Any help much appreciated, thanks in advance  Heart

Turns out, the solution in that thread I linked works great, only took me a moment to swap my function over to use jquery. Shame I have to rewrite my whole page, but it's way easier than I thought.

Apologies for the unnecessary thread - turns out I understand JS a little better than I did the last time I tied myself in knots trying to fix it.