Adding smilies in Texarea with buttons for format text and smiles

Place for comments, problems, questions, or any issue related to the JavaScript / PHP scripts from this site.
User avatar
JanMolendijk
Posts: 282
Location: Holland Rotterdam

Adding smilies in Texarea with buttons for format text and smiles

Dear admin I try to add more smilies but it seems I do something wrong.
I use the JS script from: coursesweb.net/javascript/texarea-buttons-format-text-colors-smiles_s2

I changed the first one & added a 10th item:

Code: Select all

  <img src="icos/0.gif" alt=":bb" title=":bb" class="addsmile" style="cursor:pointer;border:none;" onclick="addSmile(this)" />
  <img src="icos/1.gif" alt=":(" title=":(" class="addsmile" style="cursor:pointer;border:none;" onclick="addSmile(this)" />
  <img src="icos/2.gif" alt=":P" title=":P" class="addsmile" style="cursor:pointer;border:none;" onclick="addSmile(this)" />
  <img src="icos/3.gif" alt=":D" title=":D" class="addsmile" style="cursor:pointer;border:none;" onclick="addSmile(this)" />
  <img src="icos/4.gif" alt=":S" title=":S" class="addsmile" style="cursor:pointer;border:none;" onclick="addSmile(this)" />
  <img src="icos/5.gif" alt=":O" title=":O" class="addsmile"  style="cursor:pointer;border:none;" onclick="addSmile(this)" />
  <img src="icos/6.gif" alt=":=)" title=":=)" class="addsmile" style="cursor:pointer;border:none;" onclick="addSmile(this)" />
  <img src="icos/7.gif" alt=":|H" title=":|H" class="addsmile" style="cursor:pointer;border:none;" onclick="addSmile(this)" />
  <img src="icos/8.gif" alt=":X" title=":X" class="addsmile" style="cursor:pointer;border:none;" onclick="addSmile(this)" />
  <img src="icos/9.gif" alt=":-*" title=":-*" class="addsmile" style="cursor:pointer;border:none;" onclick="addSmile(this)" />
  <img src="icos/10.gif" alt=":b" title=":b" class="addsmile" style="cursor:pointer;border:none;" onclick="addSmile(this)" />
Into the javascript (addformat) I did this

Code: Select all

// Add code for clicked smile in element with ID passed in "id_txtfield"
function addSmile(smile) {
  // object with characters that represent the smiles, and the name of the GIF file for each one
  var smchr = {':bb':0, ':(':1, ':P':2, ':D':3, ':S':4, ':O':5, ':=)':6, ':|H':7, ':X':8, ':-*':9, ':b':10}
But by object 0 & object 10 I get this result in my textarea:

Code: Select all

<img src="icos/undefined.gif" />
I hope you could help me out.

Admin Posts: 805
The addSmile() function in that script uses uppercase letters for the name of the properties in the 'smchr' object.
Note, it has:

Code: Select all

smile.title.toUpperCase()
- JavaScript makes the difference between capital letters and lower case letters.

So, add:

Code: Select all

var smchr = {':BB':0, ':(':1, ':P':2, ':D':3, ':S':4, ':O':5, ':=)':6, ':|H':7, ':X':8, ':-*':9, ':B':10};

JanMolendijk Posts: 282
Thank you so mutch its working now

Similar Topics