Примерно так:
function p1(obj, text1, text2){
flag=1;
var text = document.selection.createRange().text;
if ((document.selection)&&(flag)) {
obj.focus();
document.postform.document.selection.createRange().text = text1+text+text2;
obj.focus();
} else obj.value +=text1+text2;
}
и вызывать функцию:
onclick="p1(this, \'\',\'\');"
не проверял