JS: How to click an image, that creates text in a textarea

Sorta like Vbulliten when clicking on the images, smilies, it creates “:)” in the textarea box. How do they do that?

To maintain flexibility, I’d do it this way.

function insertText(txt, elemID) {
	elem = document.getElementById(elemID);
	elem.value += txt;
	}
	
<form>
<textarea id="content"></textarea>
<input type="text" id="insert" /><input type="button" value="&#171; Insert this text" onClick="insertText(this.form.insert.value, 'content');" />
<input type="button id="Add Smiley :)" onClick=insertText(":)", 'content');" />
</form>

I get a syntax error

Sorry, I didn’t debug it, but it was just a couple typos

Change up the button to this

<input type="button" value="Add Smiley :)" onClick="insertText(':)', 'content');" />

works great, thanks a bunch :slight_smile:

Excuse me,
How do I use this piece of code? Where do I put the function code and where to put the rest? I always get errors when I use this code on any how,

Please help

i think you have to create a javascript file name something.js and put the function inside the javascript file. after that
<head>
<script language=“JavaScript” type=“text/javascript” src=“1.js”></script>
</head>
<form>
<textarea id=“content”></textarea>
<input type=“button” value=“Add Smiley :)” onClick=“insertText(‘<br>’, ‘content’);” />
</form>
in my code i put the function inside 1.js just do it. it will work nicely