<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert Bwtween Text</title>
<style type="text/css">
textarea,body,input{
font-family:Tahoma;
font-size:9pt;
}
</style>
<script type="text/javascript">
if(document.getElementById) {
var getRefById = function(id) {
return document.getElementById(id);
};
} else if(document.all) {
var getRefById = function(id) {
return document.all[id];
};
} else {
var getRefById = function() {
return null;
};
}
function insertText(str) {
var e = getRefById('test'), s = null, r = null;
if(e) {
if((s = document.selection) && s.createRange) {
var repos = false;
/* Element must have focus otherwise text
* will be written into other elements. */
e.focus();
if((r = s.createRange())) {
if(r.text.length) {repos = true;}
r.text = str;
/* Clear the selection to stop continuous
* overwriting of inserted text. */
if(repos && s.empty) {s.empty();}
}
} else {
e.value += str;
}
}
}
</script>
</head>
<body>
<input type="button" onclick="insertText(':)')" value=":)" />
<input type="button" onclick="insertText(':(')" value=":(" />
<br />
<textarea id="test" cols="50" rows="5"></textarea>
</body>
</html>