title: JavaScript/jQuery - replace text in input text
body: <p>Let's say we have an input field: <code>&lt;input type="text" id="id0"/&gt;</code>. I would like to dynamically replace the current selection of the text with my text. What is the best way to achieve that using jQuery or javascript?</p>
  
  <p>Update:</p>
  
  <p>I meant: the user types the text and selects part of it, then presses a button to replace the selected section with another specified text.</p>
  
  <p>Regards, Rafal</p>