# Javascript: SelectionFormField.getSelectedIndex Method

> Gets 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:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: SelectionFormField.getSelectedIndex Method
- **373 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/selectionformfield/getselectedindex-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/selectionformfield/getselectedindex-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/selectionformfield/getselectedindex-method/llms-full.txt

---

### Description

Gets 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.getSelectedIndex(<RequestNumberCallback> callback, [<ErrorCallback> errorCallback])
```

### Parameters

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

### Examples

The following example demonstrates `SelectionFormField.getSelectedIndex` in a practical document-editing workflow. It gets 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 inspectSelectedIndex(selectionFormField) {
    selectionFormField.getSelectedIndex(
        function(result) {
            console.log("get selected index result:", result);
        },
        onTxError
    );
}
```

---

## Nearby

- **Previous:** [Javascript: SelectionFormField.getItems Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/selectionformfield/getitems-method/llms-full.txt)
- **Next:** [Javascript: SelectionFormField.setEmptyWidth Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/selectionformfield/setemptywidth-method/llms-full.txt)
