0

I'm making the chat app in phone-gap, and I want to insert similes, I've inserted the similes from text area and it is being shown in body, but the issue is that when I click on similes form text area it is showing the whole path instead of title like for laughing we write :D and it shows laughing similes. When I click on laughing it shows the whole path of image but not :D (which I want). Here is my code:

 <textarea name="txtmessage" style=" width: 82%; height: auto; outline-color: none;" id="txtmessage" placeholder="write your text here..."></textarea>
                            <div class="em">
                                <img src="http://simpleicon.com/wp-content/uploads/big-smile-256x256.png" width="25" id="showhide_emobox" />
                                <div id="emobox">
                                    <img alt=":)" border="0" src="emotions/emoticon-happy.png" />
                                    <img alt=":(" border="0" src="emotions/emoticon-unhappy.png" />
                                    <img alt=":o" border="0" src="emotions/emoticon-surprised.png" />
                                </div>

                            </div>

 $('#emobox img').live("click",function () {
            var smiley = $(this).attr('alt');
            var test = $(this).attr('src');
            var tst1 = '<img alt=' + smiley + ' border=0 src=' + test + ' />'
            ins2pos(tst1, 'txtmessage');
        });
Forseth11
  • 1,418
  • 1
  • 12
  • 21

1 Answers1

0

If you just want to insert the alt of the image tag, why are you constructing a new string using the src? Why not just do this?

 $('#emobox img').live("click",function () {
        var smiley = $(this).attr('alt');
        ins2pos(smiley, 'txtmessage');
});
mpallansch
  • 1,174
  • 6
  • 16
  • i know this works for title only but i also want the image(similes) over there, but in text area i don't want to show path but title and when i click on send button it should show simile in chat body, now with above code similes are being shown but in text area it shows the whole path instead of title – Ayaz Ul Haq May 25 '15 at 17:49
  • You can't add an image to a `textarea`. You could make it a content editable `div` http://stackoverflow.com/questions/3793090/html-is-there-any-way-to-show-images-in-a-textarea or another solution is to use html entities instead of images – mpallansch May 25 '15 at 17:59