# Javascript: EditableRegionCollection.add Method

> Adds a new editable region to the document. Its position is defined through the start and length parameters. If the editable region's length is zero, the current text selection is used to define the position.

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

---

### Description

Adds a new editable region to the document. Its position is defined through the start and length parameters. If the editable region's length is zero, the current text selection is used to define the position.

### Syntax

```javascript
<void> EditableRegionCollection.add(<string> username, <number> id, <number> start, <number> length, [<AddEditableRegionCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| username | The name of the user who can edit the region. |
| id | The editable region's identifier. |
| start | Specifies the index (one-based) of the first character which belongs to the editable region. |
| length | Specifies the number of characters which belong to the editable region. |
| callback | Optional. The callback function that receives the added editable region. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example grants a user access to a deterministic text range and reports the resulting region.

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

TXTextControl.textParts.getMainText(function(mainText) {
    mainText.editableRegions.add("jsmith", 25, 1, 18, function(response, addResult) {
        response.editableRegion.getUserName(function(userName) {
            console.log("Editable region added:", {
                id: 25,
                userName: userName,
                result: addResult
            });
        }, onTxError);
    }, onTxError);
}, onTxError);
```

---

## Nearby

- **Previous:** [EditableRegionCollection Object](https://docs.textcontrol.com/ds-server/reference/javascript/editableregioncollection/llms-full.txt)
- **Next:** [Javascript: EditableRegionCollection.getItems Method](https://docs.textcontrol.com/ds-server/reference/javascript/editableregioncollection/getitems-method/llms-full.txt)
