Ho ritrovato questo esempio:
ciaocodice:<script language=javascript> var isSelected = false; function markSelection ( txtObj ) { if ( txtObj.createTextRange ) { txtObj.caretPos = document.selection.createRange().duplicate(); isSelected = true; } } function insertTag ( txtName, tag ) { if ( isSelected ) { var txtObj = eval ( "document.forms[0]." + txtName ); if (txtObj.createTextRange && txtObj.caretPos) { var caretPos = txtObj.caretPos; caretPos.text = tag+caretPos.text; markSelection ( txtObj ); if ( txtObj.caretPos.text=='' ) { isSelected = false; txtObj.focus(); } } } else { // gestione perdita focus } } </script> <form> <textarea name="tsttxt" ONSELECT="markSelection(this);" ONCLICK="markSelection(this);" ONKEYUP="markSelection(this);"></textarea> </form> <a href="javascript:" onClick="insertTag('tsttxt',':)')"> [img]smile.gif[/img] </a>