Jump to content

Javascript not Displaying all Smilies


rickmick

Recommended Posts

Does anyone know why all characters are not being replaced in my comments and the code to fix it? It displays the smilies on the first comment. The remaining comments just show the characters and not the smilies.

 

  var smilies = new Array();
smilies[''] = 'smileys/wink.gif';
smilies[''] = 'smileys/smile.gif';
smilies[''] = 'smileys/mad.gif';

function showSmilies(){
foo = document.getElementById('smiley').innerHTML;
for ( x in smilies )
{
	_search = x.replace( /(.)/g, '\\$1' );
	search = new RegExp( _search, "g" );

	foo = foo.replace( search, function(found){
		return '<img src="'+smilies[found]+'" alt="'+found+'" />';
	});
}
document.getElementById('smiley').innerHTML = foo;
}
if(window.addEventListener){
   window.addEventListener('load',showSmilies,false);
}
else {
if(window.attachEvent){
   window.attachEvent('onload',showSmilies);
  }
}

 

I have used .getelementsbytagname(body)[0] it will display all the smilies along with the ones I don't wont and it also displays the html code with it.

 

This is my html

 

  
                        <tr id="commdesc{COMMENTS.comment_id}" IF("{COMMENTS.dug}"=="-1"){style="display:none;"{:IF}IF("{COMMENTS.hide}"=="1"){style="display:none;"{:IF}><td><div id="smiley"> {COMMENTS.comment_desc}</tr></td></div>
                        
                               
                     IF("{COMMENTS.parent_id}"=="0"){<tr><td align="right"><span class="subline">[<a href="#commentbox" onClick="comreply({COMMENTS.comment_id},'{COMMENTS.username}, {COMMENTS.comment_desc}');javascript:quote('replynick','comment')">Quote</a>]</span></td></tr>{:IF}

 

Here is a pic of what it looks like attached

 

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.