How to display any selected text in alertbox in Firefox and IE both

How to display any selected text (selected text in any textbox on on form) in alertbox in Firefox and IE both?

var globalCursorPos; // global variabe to keep track of where the cursor was

    //sets the global variable to keep track of the cursor position
    function setCursorPos() {
        globalCursorPos = getCursorPos(form1.txtSuccessorExp);
    }

    //This function returns the index of the cursor location in
    //the value of the input text element
    //It is important to make sure that the sWeirdString variable contains
    //a set of characters that will not be encountered normally in your
    //text
    function getCursorPos(textElement) {
        //save off the current value to restore it later,
        var sOldText = textElement.value;

        //create a range object and save off it's text
        var objRange = document.selection.createRange();
        var sOldRange = objRange.text;

        //set this string to a small string that will not normally be encountered
        var sWeirdString = '#%~';

        //insert the weirdstring where the cursor is at
        objRange.text = sOldRange + sWeirdString; objRange.moveStart('character', (0 - sOldRange.length - sWeirdString.length));

        //save off the new string with the weirdstring in it
        var sNewText = textElement.value;

        //set the actual text value back to how it was
        objRange.text = sOldRange;

        //look through the new string we saved off and find the location of
        //the weirdstring that was inserted and return that value
        for (i = 0; i <= sNewText.length; i++) {
            var sTemp = sNewText.substring(i, i + sWeirdString.length);
            if (sTemp == sWeirdString) {
                var cursorPos = (i - sOldRange.length);
                return cursorPos;
            }
            
           
           
        }
    }

    //this function inserts the input string into the textarea
    //where the cursor was at
    function insertString(stringToInsert) {
       
        var firstPart = form1.txtSuccessorExp.value.substring(0, globalCursorPos);
        var secondPart = form1.txtSuccessorExp.value.substring(globalCursorPos, form1.txtSuccessorExp.value.length);
        form1.txtSuccessorExp.value = firstPart + stringToInsert + secondPart;

    }
    
    


    function setCaretPosition(ctrl, pos) {

        pos = document.getElementById("txtSuccessorExp").value.length;
        if (ctrl.setSelectionRange) {
            ctrl.focus();
            ctrl.setSelectionRange(pos, pos);
        }
        else if (ctrl.createTextRange) {
            var range = ctrl.createTextRange();
            range.collapse(true);
            range.moveEnd('character', pos);
            range.moveStart('character', pos);
            range.select();
        }

        FireMouseEnter(ctrl);
    }



    function FireMouseEnter(cntl) 
    {

        //alert(document.getElementById("txtSuccessorExp").value.length);
        document.getElementById("txtSuccessorExp").onclick();
    }

<asp:TextBox ID=“txtSuccessorExp” runat=“server”

                    ONCHANGE="setCursorPos();" ONCLICK="setCursorPos()"   onfocus="setCaretPosition(this,4)" &gt;&lt;/asp:TextBox&gt;

code behind
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton button = (LinkButton)e.Row.FindControl(“lnkTaskID”);
string desc = DataBinder.Eval(e.Row.DataItem, “TaskID”).ToString();
button.Attributes.Add(“onclick”, string.Format(“insertString(‘{0}’);”, desc));
}

}