# Javascript: SelectionFormField.setSelectedIndex Method

> Sets the index of the selected item of the SelectionFormField. If the property value is -1, no item is selected and the currently selected item is deselected.

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

---

### Description

Sets the index of the selected item of the SelectionFormField. If the property value is -1, no item is selected and the currently selected item is deselected.

### Syntax

```javascript
<void> SelectionFormField.setSelectedIndex(<Boolean> index, [<EmptyRequestCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| index | The index of the selected item. |
| callback | Optional. Is called when the operation completed. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `SelectionFormField.setSelectedIndex` in a practical document-editing workflow. It sets the index of the selected item of the SelectionFormField. If the property value is -1, no item is selected and the currently selected item is deselected.

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

function configureSelectedIndex(selectionFormField) {
    selectionFormField.setSelectedIndex(
        true,
        function() {
            console.log("set selected index completed.");
        },
        onTxError
    );
}
```

---

## Nearby

- **Previous:** [Javascript: SelectionFormField.setItems Method](https://docs.textcontrol.com/ds-server/reference/javascript/selectionformfield/setitems-method/llms-full.txt)
- **Next:** [SelectionFormFieldCallback Function](https://docs.textcontrol.com/ds-server/reference/javascript/selectionformfieldcallback/llms-full.txt)
