# Javascript: TextCharCollection.addControlChar Method

> Inserts a control character at the specified text input position.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: TextCharCollection.addControlChar Method
- **476 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textcharcollection/addcontrolchar-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textcharcollection/addcontrolchar-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textcharcollection/addcontrolchar-method/llms-full.txt

---

### Description

Inserts a control character at the specified text input position.

### Syntax

```javascript
<void> TextCharCollection.addControlChar(<ControlChars> controlChar, <number> textPosition, [<RequestBooleanCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| controlChar | Specifies a control character to insert. |
| textPosition | Specifies a text input position. The first input position in a document is 0. |
| callback | Optional. Receives whether the character is succesfully inserted. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `TextCharCollection.addControlChar` in a practical document-editing workflow. It inserts a control character at the specified text input position.

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

function addControlChar(textChars) {
    textChars.addControlChar(
        TXTextControl.ControlChars.Tab,
        -1,
        function(result) {
            if (result) {
                console.log("add control char is available.");
            } else {
                console.warn("add control char is not available in the current document state.");
            }
        },
        onTxError
    );
}
```

---

## Nearby

- **Previous:** [Javascript: TextCharCollection.add Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textcharcollection/add-method/llms-full.txt)
- **Next:** [Javascript: TextCharCollection.getItem Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textcharcollection/getitem-method/llms-full.txt)
