# Javascript: TextPartCollection.activate Method

> Sets the input focus to the specified text part. If the activated text part is not in the visible part of the document, the document is scrolled.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** DS Server > Reference > JavaScript API > Javascript: TextPartCollection.activate Method
- **462 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/textpartcollection/activate-method/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/textpartcollection/activate-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/textpartcollection/activate-method/llms-full.txt

---

### Description

Sets the input focus to the specified text part. If the activated text part is not in the visible part of the document, the document is scrolled.

### Syntax

```javascript
<void> TextPartCollection.activate(<FormattedText> formattedText, [<RequestBooleanCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| formattedText | Specifies which formatted text will be activated. |
| callback | Optional. Receives true, if the specified text part could be activated. Otherwise it is false. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `TextPartCollection.activate` in a practical document-editing workflow. It sets the input focus to the specified text part. If the activated text part is not in the visible part of the document, the document is scrolled.

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

function activate(formattedText) {
    TXTextControl.textParts.activate(
        formattedText,
        function(result) {
            if (result) {
                console.log("activate is available.");
            } else {
                console.warn("activate is not available in the current document state.");
            }
        },
        onTxError
    );
}
```

---

## Nearby

- **Previous:** [TextPartCollection Object](https://docs.textcontrol.com/ds-server/reference/javascript/textpartcollection/llms-full.txt)
- **Next:** [Javascript: TextPartCollection.getItem Method](https://docs.textcontrol.com/ds-server/reference/javascript/textpartcollection/getitem-method/llms-full.txt)
