I guess you're talking about JavaScript.
In JavaScript, there are several possibilities, depending on the specific browser.
The Mozilla/Firefox solution looks like this:
Code:
var selstart=txtarea.selectionStart;
var selend=txtarea.selectionEnd;
if (selstart<selend) {
selection=txtarea.value.substring(selstart, selend);
} else {
selection="";
}
And this seems to work in most of the other browsers:
Code:
selection=document.selection.createRange().text;