News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Insert Text into Editor with JavaScript

Started by Senkusha, August 16, 2010, 03:13:07 PM

Previous topic - Next topic

Senkusha

Hi all!

Rewrite:
So, I've got something that I thought was pretty simple.  I've added a dropdown and a button to my post form.  I want it to work like the Font does, where you select something, press the button, and then some text gets inserted into the post editor using JavaScript.

But, I'm not sure where I need to add the code to make that happen. 

I've got the following code in my function.php file (that I've called from the post.php)

$context['rpg_rolls'] .= '</select>&nbsp;<input type="button" name="roll_me" value="Insert Roll" onClick="roll_dice()">
    <script language="javascript" type="text/javascript">
    function roll_dice()
    {
        var result = roll_me.value;
        var t_array = new Array();
        t_array = result.split("+");
        var die1 = Math.ceil(6*Math.random());
        var die2 = Math.ceil(6*Math.random());
        var bonus = t_array[1].substring(0, (t_array[1].length - 1));
        var total = die1 + die2 + bonus;
        this.form.message.focus();
        this.form.message.value += ("Rolled: (" + result.value + ") " + die1 + ", " + die2 + "= Total:" + total);
    }
    </script>';


I'm really rusty on JavaScript, so I don't even know if this is going to work
Can anybody lend me a hand?  Thanks!
-- Senkusha
The Kawaii Klub
The Creative Anime Role Playing Community.
(SMF v. 2.1.4, PHP v. 8.0)

live627


Senkusha

DUH!  I can't believe I forgot that!!!

2.0 RC 3
-- Senkusha
The Kawaii Klub
The Creative Anime Role Playing Community.
(SMF v. 2.1.4, PHP v. 8.0)

Senkusha

Anybody?  I hope I was clear enough on what I'm wanting to do.

Thanks!
-- Senkusha
The Kawaii Klub
The Creative Anime Role Playing Community.
(SMF v. 2.1.4, PHP v. 8.0)

Senkusha

Okay, I found part of my problem.  My text appears when I toggle off the WYSIWYG editor.  How can I make my text appear on the editor?

It's obviously not document.postmodify.message.value

Thanks!
-- Senkusha
The Kawaii Klub
The Creative Anime Role Playing Community.
(SMF v. 2.1.4, PHP v. 8.0)

Senkusha

There has to be a solution to this problem.  Can anybody point me in the right direction?  Please? 

Thank you!
-- Senkusha
The Kawaii Klub
The Creative Anime Role Playing Community.
(SMF v. 2.1.4, PHP v. 8.0)

Oya

so oEditorHandle_message is th eobject in teh regular post paeg since teh $context['post_box_name'] is message

Advertisement: