<p>I have a textbox and a link button.
When I write some text, select some of it and then click the link button, the selected text from textbox must be show with a message box.</p>
<p>How can I do it?</p>
<hr />
<p>When I click the submit button for the textbox below, the message box must show <em>Lorem ipsum</em>. Because &quot;Lorem ipsum&quot; is selected in the area.</p>
<hr />
<p>If I select any text from the page and click the submit button it is working, but if I write a text to textbox and make it, it's not. Because when I click to another space, the selection of textbox is canceled.</p>
<p>Now problem is that, when I select text from textbox and click any other control or space, the text, which is selected, must still be selected.</p>
<p>How is it to be done?</p>

For Opera, Firefox and Safari, you can use the following function:
```
```
function getTextFieldSelection(textField) {
    return textField.value.substring(textField.selectionStart, textField.selectionEnd);
}
```
```
Then, you just pass a reference to a text field element (like a textarea or input element) to the function:
```
```
alert(getTextFieldSelection(document.getElementsByTagName("textarea")[0]));
```
```
Or, if you want <textarea> and <input> to have a getSelection() function of their own:
```
```
HTMLTextAreaElement.prototype.getSelection = HTMLInputElement.prototype.getSelection = function() {
    var ss = this.selectionStart;
    var se = this.selectionEnd;
    if (typeof ss === "number" && typeof se === "number") {
        return this.value.substring(this.selectionStart, this.selectionEnd);
    }
    return "";
};
```
```
Then, you'd just do:
```
```
alert(document.getElementsByTagName("textarea")[0].getSelection());
alert(document.getElementsByTagName("input")[0].getSelection());
```
```
for example.