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
https://forums.phpfreaks.com/topic/245709-javascript-not-displaying-all-smilies/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.