The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

chatbox button

View previous topic View next topic Go down

Solved chatbox button

Post by niquon715 on April 9th 2015, 2:25 am

Code:
$(function() {
var Rolltxt = '<div id="Rolled">ROLL MESSAGE</div>';
$('#quick_reply input[value="Send"]').after('<input id="Roll" class="mainoption" style="margin-left:6px;" type="submit" value="Roll" name="post"></input>');
$('#Roll').click(function() {
$('#quick_reply textarea').val(Rolltxt);
$('#quick_reply i-frame').contents().find('body').html(Rolltxt);
});

});


lets take this coding and change so it shows up as a button on the chatbox i tried by just changing a few lines

Code:
$(function() {
var Rolltxt = '<div id="Rolled">ROLL MESSAGE</div>';
$('#chatbox input[value="Send"]').after('<input id="Roll" class="mainoption" style="margin-left:6px;" type="submit" value="Roll" name="post"></input>');
$('#Roll').click(function() {
$('#chatbox textarea').val(Rolltxt);
$('#chatbox i-frame').contents().find('body').html(Rolltxt);
});

});

where i want the button to show uphttp://prntscr.com/6reo7s


Last edited by niquon715 on April 9th 2015, 11:34 am; edited 1 time in total

niquon715
Forumember

Posts : 83
Reputation : 10
Language : english

http://celestialfireacademy.forumotion.com/forum

Back to top Go down

Solved Re: chatbox button

Post by Ange Tuteur on April 9th 2015, 9:39 am

Your script isn't going to work, because the scripts installed via JS codes management don't affect the chatbox. You generally need to access the frame of the chatbox to manipulate its contents. Here's an example I can give you of accessing the frame, creating a button, and manipulating the frame contents :

Modules > JS codes management > new

Placement : In the index
Code:
$(function() {
  var frame = document.getElementById('frame_chatbox'), fa, bloc, button, msg; // define all our variables
 
  frame.onload = function() {
    frame.contentDocument ? fa = frame.contentDocument : fa = frame.contentWindow.document; // determine which method to use to access the frame
   
    // find and create our elements
    bloc = fa.getElementById('chatbox_messenger_form'), msg = fa.getElementById('message'), button = document.createElement('INPUT');
   
    button.type = 'button'; // input type
    button.value = 'myButton'; // button texte
   
    // code to be executed when our button is clicked
    button.onclick = function() {
      msg.value += ' myButton\'s text'; // adds to the current message value
    };
   
    bloc.appendChild(button); // append the button to the message form
  };
});

I've marked the code with comments to give an explanation. Smile

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: chatbox button

Post by Ange Tuteur on April 13th 2015, 7:39 am

Topic marked solved ; Archived.

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum