# Javascript: FormFieldCollection.addSelectionFormField Method

> Adds a new SelectionFormField.

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

---

### Description

Adds a new [SelectionFormField](https://docs.textcontrol.com/ds-server/reference/javascript/selectionformfield/llms-full.txt).

### Syntax

```javascript
<void> FormFieldCollection.addSelectionFormField(<Number> emptyWidth, [<RequestSelectionFormFieldCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| emptyWidth | Specifies the horizontal extension, in twips, of the SelectionFormField, when there is no selected item. When this parameter is set to 0, a default value is used. |
| callback | Optional. Receives the added SelectionFormField. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example inserts a priority drop-down field and selects its initial value.

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

TXTextControl.textParts.getMainText(function(mainText) {
    mainText.formFields.addSelectionFormField(1440, function(priorityField) {
        priorityField.setItems(["Low", "Medium", "High"], function() {
            priorityField.setSelectedIndex(1, function() {
                console.log("Priority field added with Medium selected.");
            }, onTxError);
        }, onTxError);
    }, onTxError);
}, onTxError);
```

---

## Nearby

- **Previous:** [Javascript: FormFieldCollection.addDateFormField Method](https://docs.textcontrol.com/ds-server/reference/javascript/formfieldcollection/adddateformfield-method/llms-full.txt)
- **Next:** [Javascript: FormFieldCollection.addTextFormField Method](https://docs.textcontrol.com/ds-server/reference/javascript/formfieldcollection/addtextformfield-method/llms-full.txt)
