# Dropdown selected value property returns array format in perspective

**URL:** <https://forum.inductiveautomation.com/t/dropdown-selected-value-property-returns-array-format-in-perspective/54347>\
**Category:** Ignition\
**Created:** [December 21, 2021, 9:53am UTC](https://forum.inductiveautomation.com/t/dropdown-selected-value-property-returns-array-format-in-perspective/54347 "2021-12-21T09:53:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anita.Shinde](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@Anita.Shinde](https://forum.inductiveautomation.com/u/Anita.Shinde)\
**Post date:** [December 21, 2021, 9:53am UTC](https://forum.inductiveautomation.com/t/dropdown-selected-value-property-returns-array-format-in-perspective/54347/1 "2021-12-21T09:53:57Z")

</div>

Hi,  
I am using one multiselect dropdown.  
Through scripting I have created one list and binding that list to multiselect dropdown options.  
Now I want to check the selected value of multiselect dropdown, So on change script I am trying to get selected value but when I checked by printing, selected value returns below array format value.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/0/b090c932779367ce750245447945cc534a24ece8.png)

Here have selected 0th index.  
How can I get int 0 value from this, Any idea?

Like this I am binding values to dropdown.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/8/582d4d0fa709eed5c6ad0425f38b0f6b4de90e4f.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [December 21, 2021, 12:08pm UTC](https://forum.inductiveautomation.com/t/dropdown-selected-value-property-returns-array-format-in-perspective/54347/2 "2021-12-21T12:08:17Z")

</div>

Indexing it with `[0]` should be enough.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 21, 2021, 4:57pm UTC](https://forum.inductiveautomation.com/t/dropdown-selected-value-property-returns-array-format-in-perspective/54347/3 "2021-12-21T16:57:36Z")

</div>

You need to treat the value of the dropdown just like you would any other array in python.

For example, I have a Dropdown with with the following structure for `options`:

```auto
[
  {
    "value": 1,
    "label": "One"
  },
  {
    "value": 2,
    "label": "Two"
  },
  {
    "value": 3,
    "label": "Three"
  }
]

```

A user has selected “One” and “Two”, so `props.value` is an array which contains `1` and `2` as the values of the selected options.

```auto
value: [
    1,
    2
]

```

To reference those value, you should either directly reference them via index, or loop over the list.

```auto
# this script in onChange Script
try:
    system.perspective.print("First selected value: {0}".format(currentValue.value[0]))
    if len(currentvalue.value) > 1:
        # the following attempts at iterating over the selected values should be identical
        # 1
        [system.perspective.print("Selected value: {0}".format(entry)) for entry in currentValue.value]
        # 2
        for entry in currentValue.value:
            system.perspective.print("Selected value: {0}".format(entry))
        # 3
        for i in range(len(currentValue.value)):
            system.perspective.print("Selected value: {0}".format(currentValue.value[i]))
except IndexError:
    system.perspective.print("No values selected")

```

---

<div class="post-metadata">

**Author:** ![Anita.Shinde](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@Anita.Shinde](https://forum.inductiveautomation.com/u/Anita.Shinde)\
**Post date:** [December 22, 2021, 6:58am UTC](https://forum.inductiveautomation.com/t/dropdown-selected-value-property-returns-array-format-in-perspective/54347/4 "2021-12-22T06:58:20Z")

</div>

No, I cant pass hardcode index, It should be dynamic.  
I want selected value(of any index) from dropdown so that I can access label of that particular index.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [December 22, 2021, 8:49am UTC](https://forum.inductiveautomation.com/t/dropdown-selected-value-property-returns-array-format-in-perspective/54347/5 "2021-12-22T08:49:04Z")

</div>

So, let me try to make things clear:  
You want a multiple selection dropdown, and what you need to get out of it is the list of LABELS that were selected ? Not the values ? Are the values used in any way ?

I suggest populating your dropdown like this

```python
# Whatever processing takes place before the snippet you showed us and that results in `outputdata`
# If it's the results of processing, you might as well use a pyDataSet so that it's easier to manipulate.
return [
    {
        'value': wcenter,
        'label': wcenter
    } for wcenter in outputdata
]

```

This is a ROUGH example. You might need to cast to string as you did before, though that could be done earlier in the building of `outputdata`.  
You could also rework the label a bit, maybe something like `{'label': wcenter.replace('_', ' ')}`, things like that.  
Now you can use the `label` for display only, and use `value` for your things.

Bind something to `dropdown.props.values` and you’ll get a list of those `wcenter`, that you can iterate through like this:

```python
for value in dropdown.prop.values:
    do_something(value)

```

And you’ll get every `wcenter` that was selected.

If you really need to have a number associated to your wcenters:

```python
return [
	{
		'label': wcenter,
		'value': {
			'index': i,
			'name': wcenter
		}
	} for i, wcenter in enumerate(outputdata)
]

```

Now when entries are selected in the dropdown, you’ll get a list that looks like this:

```json
[
  {
    'index': x,
    'name': "center foo"
  },
  {
    'index': y,
    'name': "center bar"
  }
]

```

That you can iterate through:

```python
for index, name in values.items():
    do_something(index, name)

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 22, 2021, 3:39pm UTC](https://forum.inductiveautomation.com/t/dropdown-selected-value-property-returns-array-format-in-perspective/54347/6 "2021-12-22T15:39:17Z")

</div>

> [@Anita.Shinde](#):
>
> No, I cant pass hardcode index, It should be dynamic.

Where did I use a hard-coded index?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [December 22, 2021, 4:07pm UTC](https://forum.inductiveautomation.com/t/dropdown-selected-value-property-returns-array-format-in-perspective/54347/7 "2021-12-22T16:07:24Z")

</div>

I did, she was probably replying to me.
