Need help with Javascript!

ILikeSprite

Banned
Oct 14, 2001
1,772
0
0
How do I make it so when you click on an image it places text into a messagebox? For example, I am modifing my Fusetalk forums and I want to make it so when you click a smiley it places the text needed to be entered to get that smiley.
 

Ramius

Senior member
Feb 13, 2001
318
0
0
From your post I think you mean to show a popup with text in it...?

Your image tag in the <Body> would look like this:
<IMG id="smiley" OnClick="messagePop(this)" SRC="smiley.gif">

Inside the <head> tag, put this:
<script language=javascript>
function messagePop(image)
{
if ( image.id == "smiley")
alert("enter the text you want to display here.");
}
</script>

You can just use the same function for other images, just give them an ID, add the OnClick part, and add another "if" statement in messagePop()

Let me know if I misunderstood what you wanted to do...
 

ILikeSprite

Banned
Oct 14, 2001
1,772
0
0
I want it to enter the text for the smiley into the reply box. Like :) would enter ": )" without the space.....
 

Ramius

Senior member
Feb 13, 2001
318
0
0
Crap, I think I misuderstood you...

You would just need to add to the text already in the message box.

If its a textarea, you would have to change the InnerHTML of the area, such as:
Lets say your textarea has an ID of "messagebox".

Your function would do this:

messagebox.innerHTML = messagebox.innerHTML + "whatever you wanted to add here" ;


all in one tag: <img src=smiley.gif OnClick="messagebox.innerHTML = messagebox.innerHTML + ': )' ">
 

Ramius

Senior member
Feb 13, 2001
318
0
0
Up to you, you can put it in a function or all in one tag (look at the bottom of my previous reply)

If you go the function route:

<head>
<script language=javascript>
function addsmiley(imageid)
{
if (imageid == "smiley")
messagebox.innerHTML = messagebox.innerHTML + ": )"
}
</script>
</head>
<body>

<img src=smiley.gif id=smiley OnClick="addsmiley(this.id)" >
<TEXTAREA id=messagebox rows=2 cols=20></TEXTAREA>

</body>

you can cut and paste the code above in a blank HTML page to see it work.