Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clicking on Smiley Makes Code show up on MSG board 1

Status
Not open for further replies.

xstranded

Technical User
Oct 26, 2003
15
0
0
US
hi Again everyone... i wanna say thanks to everyone who helped me before on my first question. but yet again i have another one...

on my website, i have a Tag Board, and i have Smilies for it also... right now for you to put the smiley in your MSG you either have to type the code, or copy and paste. is there a way so that a user can simply click on the smiley and make it pop up in the "comment box"??

And Again Thank You Very Much

\\||//::xstranded
======its the bind between art and soul
//||\\and the union of body and sound
<::>
 
Are you looking for something like this?
Code:
<script type=&quot;text/javascript&quot;>

function addSmiley() {

	area = document.getElementById( &quot;test&quot; );
	area.value += &quot;:o)&quot;;
}

</script>

<textarea id=&quot;test&quot;>Test. </textarea>

<a onclick=&quot;addSmiley();&quot;>Add Smiley</a>

HTH.
 
your solution is SOOOO CLOSE man... alright the only problem that i'm coming across is the

area.value += &quot;&quot;;

when i put a value in this field it will use only that value for every link. so let's say i want a Wink Smiley, and i put the value

area.value += &quot;:D&quot;;

then in the object i put the
<a onclick=&quot;addSmiley();&quot;>Wink</a>

instead of getting a Wink, i'll get a BIG GRIN smile, because of the

area.value += &quot;&quot;;

is there a way to make the onclick=&quot;...&quot; equal what each smiliey is... if anyone wants, check out my site below, click on &quot;shoutkast&quot; and take a look. the first alien head is the one to just click... it works, but i have to put a Defined Value in the area.value, and i dont want to, i want it to be whatever smiley the user clicks on...

i've been trying to figure it out, been drivin me kinda looney... hehe thanks for the help again

\\||//::xstranded
======its the bind between art and soul
//||\\and the union of body and sound
<::>
 
Just pass the smiley code to the function.

Like this:
Code:
<script type=&quot;text/javascript&quot;>

function addSmiley( code ) {

    area = document.getElementById( &quot;test&quot; );
    area.value += code;
}

</script>

<textarea id=&quot;test&quot;>Test. </textarea>

<a onclick=&quot;addSmiley( ':frog:' );&quot;>Frog</a>
<a onclick=&quot;addSmiley( ':toad:' );&quot;>Toad</a>
 
How about storing the textual value (eg ':)' ) of each smiley in the img's alt tag. The extra bonus of this is folks with images off get the correct text representation of the smiley :D

Try this out:
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd&quot;>[/URL]
<html>
<head>
<title>Test Bed</title>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
function addSmiley(imgTag) {
    var area = document.getElementById( &quot;test&quot; );
    area.value += imgTag.alt;
}
</script>
</head>
<body>
<form name=&quot;myForm&quot; onsubmit=&quot;return false;&quot;>
<img src=&quot;imgs/smiley.gif&quot; alt=&quot;:)&quot; onclick=&quot;addSmiley(this);&quot;>
<img src=&quot;imgs/elvis.gif&quot; alt=&quot;2:]&quot; onclick=&quot;addSmiley(this);&quot;>
<textarea id=&quot;test&quot; name=&quot;myText&quot; rows=&quot;4&quot; cols=&quot;60&quot;></textarea>
</form>
</body>
</html>

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
this is being a real pain in the a$$... i can't seem to get it to work. i'll show you just the top part of my HTML. i mean it's how you have it... but the whole self define thing isnt working. i have no clue on what to do... i believe this is a lost cause...

<html>
<head>
<title>ShoutKast</title>
<link rel=&quot;stylesheet&quot; href=&quot;shoutkast.css&quot;>
<SCRIPT>
function popUp(URL) {
day = new Date();
id = day.getTime();
eval(&quot;page&quot; + id + &quot; = window.open(URL, '&quot; + id + &quot;', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=170,height=300');&quot;);
}

</SCRIPT>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
function addSmiley(imgTag) {
var area = document.getElementById( &quot;comment&quot; );
area.value += imgTag.alt;
}
</script>

</head>
<body>
<div align=&quot;right&quot;><br>
<a class=&quot;head&quot;>Shoutkast</a><br>
<br>
</div>
<div style=&quot;position: absolute; left: 3; top: 100&quot;>
<table width=&quot;290&quot; height=&quot;218&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td><form action=&quot;sign.php&quot; method=&quot;GET&quot; target=&quot;tags&quot;>
<div id=&quot;Layer1&quot; style=&quot;border-width: 1 1 1 1; border-color: #C5DBF2; border-style: solid; width: 218;&quot;>
<iframe src=&quot;tags.php?show=limit&quot; name=&quot;tags&quot; width=&quot;290&quot; height=&quot;130&quot; frameborder=&quot;0&quot; ></iframe>
</div>
<input type=&quot;text&quot; size=&quot;25&quot; name=&quot;name&quot; value=&quot;name&quot; class=&quot;input&quot; maxlength=&quot;15&quot;><br>
<input type=&quot;text&quot; size=&quot;25&quot; name=&quot;website&quot; value=&quot; class=&quot;input&quot;><br>
<input type=&quot;text&quot; size=&quot;25&quot; name=&quot;comment&quot; value=&quot;comment&quot; class=&quot;input&quot; maxlength=&quot;150&quot; id=&quot;comment&quot;><br>
<input type=&quot;submit&quot; value=&quot; shout &quot; class=&quot;button&quot;> <a href=&quot;tags.php?show=all&quot; onclick=&quot;popUp(this.href);return false;&quot;>a</a> | x | <a href=&quot;admin.php&quot; target=&quot;blank&quot;>.</a>
</form>
</td>
</tr>
</table>
</div>
<div style=&quot;position: absolute; left: 300; top: 70;&quot; align=&quot;center&quot;>
<table width=&quot;91&quot; height=&quot;248&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; bordercolor=&quot;#FFFFFF&quot;>
<tr valign=&quot;middle&quot;>
<td><div align=&quot;center&quot;><img src=&quot;smilies/alien1.gif&quot; alt=&quot;:a&quot; onclick=&quot;addSmiley( &quot;:a&quot;);&quot; width=&quot;15&quot; height=&quot;15&quot;></div></td>
<td><div align=&quot;center&quot;><font size=&quot;1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>:a</font></div></td>
</tr>
<tr align=&quot;center&quot; valign=&quot;middle&quot;>
<td><a onclick=&quot;addSmiley( ';a' );&quot;><img src=&quot;smilies/alien2.gif&quot; width=&quot;15&quot; height=&quot;15&quot;></a></td>
<td><font size=&quot;1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>;a</font></td>
</tr>

now when i click on the second smiley face... i get a &quot;undefined&quot; in my comment box. i know why that shows up, because i have it a different way then the ALT way. but i can't get either one to work... if you guys think i should stop trying to figure out.. let me know, my head will hurt less... thanks again

\\||//::xstranded
======its the bind between art and soul
//||\\and the union of body and sound
<::>
 
the image tag should be like this:

<img src=&quot;smilies/alien1.gif&quot; alt=&quot;:a&quot; onclick=&quot;addSmiley(this);&quot; width=&quot;15&quot; height=&quot;15&quot;>

just replace the smiley characters argument in addSimley() by addSimely(this) in all smiley image tag.
 
You've mixed up your img tags. If you are using an alt tag as the text to be added, and my function to add what's in the alt tag into the comment, then you need to get your img tags the way I showed in my example.

So
[tt]<a onclick=&quot;addSmiley( ';a' );&quot;>[/tt]
- Won't work because the addSmiley() is looking for a reference to an <img> tag object
And
[tt]<img src=&quot;smilies/alien1.gif&quot; alt=&quot;:a&quot; onclick=&quot;addSmiley( &quot;:a&quot;);&quot; width=&quot;15&quot; height=&quot;15&quot;>[/tt]
Will break twice over, once because like above there is no reference to the img tag (the this in my example), and twice because you're mixing &quot;s with more &quot;s within themselves, you need to escape them \&quot; or use ' single quotes for the inner set.

Both of these img tags should be like:
[tt]
<img src=&quot;smilies/alien1.gif&quot; alt=&quot;:a&quot; onclick=&quot;addSmiley( this);&quot; width=&quot;15&quot; height=&quot;15&quot;>
[/tt]
if you want to use the version of addSmiley() you posted in your code example.

Hope that clears things up.

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
ALRIGHT !!!! hehehe, fixed it :) i have to apoligize for being so illiterate, i didnt realize
alt=&quot;:a&quot; onclick=&quot;addSmiley( this);&quot;

that the &quot;this&quot; had to stay there :D but now it works. Thank you All very much for sticking with me and helping me. i really do appreciate it. i hope i can help you guys out with anything.

-Nguyen

\\||//::xstranded
======its the bind between art and soul
//||\\and the union of body and sound
<::>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top