Se, come immagino, il codice ti serve a inserire del testo (tipo smile, tags, etc.) in una textarea, potresti partire dal consiglio di TrueLies e integrarlo con questo codice:
[CODE]<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Esempio per il Forum di HTML.it</title>
<script type="text/javascript">
function insertMetaChar(sStartTag, sEndTag) {
var bDouble = arguments.length > 1, oMsgInput = document.myForm.myTxtArea, nSelStart = oMsgInput.selectionStart, nSelEnd = oMsgInput.selectionEnd, sOldText = oMsgInput.value;
oMsgInput.value = sOldText.substring(0, nSelStart) + (bDouble ? sStartTag + sOldText.substring(nSelStart, nSelEnd) + sEndTag : sStartTag) + sOldText.substring(nSelEnd);
oMsgInput.setSelectionRange(bDouble || nSelStart === nSelEnd ? nSelStart + sStartTag.length : nSelStart, (bDouble ? nSelEnd : nSelStart) + sStartTag.length);
oMsgInput.focus();
}
</script>
<style type="text/css">
.intLink {
cursor: pointer;
text-decoration: underline;
color: #0000ff;
}
</style>
</head>
<body>
<form name="myForm">
[<span class="intLink" onclick="insertMetaChar('[B]','[\/B]');">grassetto</span> | <span class="intLink" onclick="insertMetaChar('[I]','[\/I]');">corsivo</span> | <span class="intLink" onclick="insertMetaChar('[URL='+prompt('Enter the full URL for the link')+']','[\/URL]');">collegamento</span> | <span class="intLink" onclick="insertMetaChar('\n
codice:
\n','\n[\/CODE]\n');">codice</span> | <span class="intLink" onclick="insertMetaChar(' :-)');">smile</span> | etc. etc.]</p>
<textarea rows="10" cols="50" name="myTxtArea">Testo di esempio</textarea></p>
</form>
</body>
</html>