Displaying the user selected text
<pre><code> &lt;script type="text/javascript"&gt;
        /* run on document load **/
        function disp() {
            //var text = document.getElementById('TextArea1').value;

            var text = document.getElementById('MainContent_TextArea1').value;
            //alert('a')

            if (text == null)
            {
                return false;
            } 
            else
            {
                var t = text;
          var t = text.substr(text.selectionStart, text.selectionEnd -text.selectionStart);
               document.getElementById('displayval').value = t;
                 alert(t)
                }
            }
  &lt;/script&gt;
    &lt;div&gt;
    &lt;input id="TextArea1" runat="server" type="text"/&gt;
    &lt;INPUT type="button" onclick= "disp()" visible="true" value="Show"/&gt;
    &lt;INPUT type="text"  id ="displayval" visible="true" /&gt;
    &lt;/div&gt;
</code></pre>

<p>Here I am trying to display the Text which is selected by user. But unfortunately in var t = text.substr(text.selectionStart, text.selectionEnd -text.selectionStart); getting error.
It is not working. Any wrong in this code. Please help me with correcting this..</p>