Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8895865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:53:46+00:00 2026-06-14T23:53:46+00:00

I have a textarea where users can type content and also include emoticon symbols

  • 0

I have a textarea where users can type content and also include emoticon symbols like 🙂 or 😉

When ‘Sent’ is pressed the textarea string needs to be parsed to convert any emoticon symbols into <img>‘s for display.

I can easily generate a list of emoticons and there relevant image like:

 ':)' - '<img src="/images/happy.jpg"/>'
 ';)' - '<img src="/images/wink.jpg"/>'

I assume the above could be put into an associate array.

Can someone point me in the right direction to create an associate array of emoticon symbol’s and html img tags and then parse a string to replace the matching symbols with the html img tags?

Also out of interest is there a better way to do this?

thankyou

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:53:47+00:00Added an answer on June 14, 2026 at 11:53 pm

    You actually quite described the behavior:

    var map = {
        ':)':   '<img src="/images/happy.jpg"/>',
        ';(':   '<img src="/images/wink.jpg"/>'
    },
    text    = document.getElementsByTagName('textarea')[ 0 ].value;
    
    Object.keys( map ).forEach(function( ico ) {
        // escape special characters for regex
        var icoE   = ico.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
        // now replace actual symbols
        text       = text.replace( new RegExp(icoE, 'g'), map[ico] );
    });
    

    Example: http://jsfiddle.net/DBfpw/2/


    Edit
    In order to have a valid regular expression created, we need to escape ) and (

    Note
    The above snippet contains ECMAscript5 featured code. If you need to run that on legacy browsers, make sure to include a ES5 Shim library.

    Note 2
    Sorry the above code does not contain any jQuery code since its not necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textarea and users can type in it. I want to store
I have a textarea within an HTML page into which my users paste content.
I have a text area in which users can type source code (html/css/js). I
I have a textarea in an ASP.NET MVC Application where the user can type
So, I have a textarea that users are supposed to type codes into. Ex:
I have <textarea> where user can type in his message to the world! Below,
I have a textarea, where the user can add their comments. Now after adding
I have an issue where i have a textarea in a form where users
I have an and users can login and view their own profile with a
I have used MarkiItUp to build a jquery editor. Now when user type content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.