<script type="text/javascript">
        /* 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)
                }
            }
  </script>
    <div>
    <input id="TextArea1" runat="server" type="text"/>
    <INPUT type="button" onclick= "disp()" visible="true" value="Show"/>
    <INPUT type="text"  id ="displayval" visible="true" />
    </div>
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..
 
    