# Javascript: Selection.setText Method

> Sets the currently selected text.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 26.0
- **Path:** DS Server > Reference > JavaScript API > Javascript: Selection.setText Method
- **315 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/selection/settext-method/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/selection/settext-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/selection/settext-method/llms-full.txt

---

### Description

Sets the currently selected text.

### Syntax

```javascript
<void> Selection.setText(<string> text, [<EmptyRequestCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| text | The text. |
| callback | Optional. Is called when the operation completed. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `Selection.setText` in a practical document-editing workflow. It sets the currently selected text.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.selection.setText(
    "Quarterly report",
    function() {
        console.log("set text completed.");
    },
    onTxError
);
```

---

## Nearby

- **Previous:** [Javascript: Selection.setStrikeout Method](https://docs.textcontrol.com/ds-server/reference/javascript/selection/setstrikeout-method/llms-full.txt)
- **Next:** [Javascript: Selection.setTextBackColor Method](https://docs.textcontrol.com/ds-server/reference/javascript/selection/settextbackcolor-method/llms-full.txt)
