<script type="text/javascript">
function insert(el,ins) {
if (el.setSelectionRange){
el.value = el.value.substring(0,el.selectionStart) + ins + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length);
}
else if (document.selection && document.selection.createRange) {
el.focus();
var range = document.selection.createRange();
range.text = ins + range.text;
}
}
</script>
<form>
<input type="button" value="hello" onclick="insert(this.form.ta,'hello')">
<input type="button" value="my freind" onclick="insert(this.form.ta,'my friend')">
<br />
<textarea rows="7" cols="30" name="ta">
This is sample text, click anywhere in here then
choose on of the buttons above to see text inserted.
</textarea>
</form>