AJAX jQuery click results in function event being fired twice
- by pmagunia
I have an AJAX chat room module in Drupal and I am trying to insert BBCode stlye tex tags to the submit box when the user clicks Insert Tex. I managed to get the following code to work the first time but afterwards when I click Insert Tex it inserts the tex tags triple times.
$('#edit-chatroom-message-entry-submit').click(function (e) {
e.preventDefault();
e.stopPropagation();
if ($('#edit-chatroom-message-entry-box').val()){
Drupal.chatroom.postMessage($('#edit-chatroom-message-entry-box').val());
$('#edit-chatroom-message-entry-box').val('').focus();
}
});
$('#edit-chatroom-tex-submit').click(function (e) {
e.preventDefault();
e.stopPropagation();
$('#edit-chatroom-message-entry-box').val($('#edit-chatroom-message-entry-box').val() + '[tex][/tex]');
});
I would appreciate it if a suggestion could be make to make the code work properly.