 <p>By using <a href="http://plugins.jquery.com/project/jCaret" rel="nofollow">JQuery Caret Plugin</a>, you could use some code like:</p> <pre><code>&lt;textarea id="codeInput" cols="80" rows="50"&gt;content&lt;/textarea&gt; &lt;script type="text/javascript"&gt; var tagDict = { "[b]" : "[/b]", "[c]" : "[/c]", "[d]" : "[/d]" }; $(document).ready(function () { $('#codeInput').keyup(function () { var test = $(this).val(); var tagStart = test.substr(test.length - 3, 3); if (tagDict[tagStart]) { $(this).val(test + tagDict[tagStart]); $(this).caret(test.length, test.length); } }); }); &lt;/script&gt; </code></pre> <p>It's not perfect, but it could be a start for a complete code completion function.</p>