MyBB Community Forums

Full Version: Emoji replacing text
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I have this piece of code which insers a specified emoji into a input field (text).

jQuery("img.smilie").click(function () {
 var emoji_value = jQuery(this).attr('data-emojiname');
$('#insert_emoji').val(''+emoji_value+'');
});

However, when you're typing something like: "Hello!" and then you click on a emoji, it replaces the whole text with just the emoji + it won't work with multiple emojis.

Here's a video:

https://u.pomf.is/lbyame.mp4

Thank you for reading.  Smile
That's because you're setting the value to just the emoji value.

Try:
jQuery("img.smilie").click(function () {
  var current_input_value = jQuery("#idOfInput").val();
  var emoji_value = jQuery(this).attr('data-emojiname');
  $('#insert_emoji').val(current_input_value + emoji_value);
});

Obviously change the "#idOfInput" to the actual ID of your input box.