title: How to get selected/highlighted text from <textarea> using Javascript?
body: <p>I have a <code>&lt;textarea&gt;</code> which I want to use as a editing panel similar to the ones found in most bulletin boards and forums (even like the one in here). There has to be a 'bold text' button which should bold the currently selected/highlighted text in the <code>&lt;textarea&gt;</code>.</p>
  
  <p>How do I do so using javascript.</p>
  
  <p>For example if the following belongs in the <code>&lt;body&gt;</code>-</p>
  
  <pre><code>&lt;textarea id="txtArea"&gt;Some text here.&lt;/textarea&gt;
  &lt;input type="button" id="btnCmd" onclick="boldthis('txtArea');" value="Bold"&gt;
  </code></pre>
  
  <p>How do I complete the javascript code <code>function boldthis(elementid){}</code> so I can do
  at least collect the selected text in <code>&lt;textarea id="txtArea"&gt;</code>?</p>
  
  <p><em>You may or may not use the example I used to describe your explaination, as long as I understand the logic. Thanks for reading.</em></p>