# Get selected text in dropdown component

**URL:** <https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [December 14, 2022, 3:03pm UTC](https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612 "2022-12-14T15:03:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwb](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dwb](https://forum.inductiveautomation.com/u/dwb)\
**Post date:** [December 14, 2022, 3:03pm UTC](https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612/1 "2022-12-14T15:03:35Z")

</div>

Hi,  
I have a dropdown component and I'd like to get the selected text.  
The problem is that my dropdown values are not 0,1,2,3 etc. I have random values, like the first row has the value1651, second row 1700 (just as examples), etc.  
How can I get the selected text? Thanks.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 14, 2022, 3:36pm UTC](https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612/2 "2022-12-14T15:36:10Z")

</div>

The `props.value` will always hold the selected value(s), are you wanting the selected Label(s)?

Is the dropdown set for multiselection?

---

<div class="post-metadata">

**Author:** ![dwb](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dwb](https://forum.inductiveautomation.com/u/dwb)\
**Post date:** [December 14, 2022, 4:20pm UTC](https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612/3 "2022-12-14T16:20:44Z")

</div>

Hi,  
Yes, I can see the selected values using "props.value". But I'd like to get the selected label(s).  
It's not set for multiselection.  
Thanks.

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [December 14, 2022, 4:38pm UTC](https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612/4 "2022-12-14T16:38:11Z")

</div>

How is your dropdown populated ? SQL query or manually entered in the props etc?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 14, 2022, 4:42pm UTC](https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612/5 "2022-12-14T16:42:29Z")

</div>

Something along these lines should do the trick, assuming that your options are a list of objects. If they are a dataset then it will need to be modified slightly.

```python
for option in self.props.options:
    if option.value == self.props.value:
         self.custom.selectedLabel = option.label
        return

```

With a dataset you could potentially use an expression binding with the `lookup()` expression function.

---

<div class="post-metadata">

**Author:** ![dwb](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dwb](https://forum.inductiveautomation.com/u/dwb)\
**Post date:** [December 14, 2022, 4:43pm UTC](https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612/6 "2022-12-14T16:43:06Z")

</div>

It is populated by a query, it's not populated manually.

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [December 14, 2022, 5:01pm UTC](https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612/7 "2022-12-14T17:01:39Z")

</div>

If your not interested in what the value is and only want the label you can modify your SQL so the label and value match, you can then use the value prop.

```auto
Select name as 'value', name as 'label'

```

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [December 14, 2022, 5:37pm UTC](https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612/8 "2022-12-14T17:37:19Z")

</div>

Another method..

On the dropdown create a custom property called `displayvalue`.

On the dropdown value prop, right click and add a change script.

```auto
	data = self.props.options
	for row in range(data.getRowCount()):
		if (data.getValueAt(row, "value") == self.props.value):
			self.custom.displayvalue = data.getValueAt(row, "label")
			break

```

That should then update the custom property with the label.

Credit goes to the below, there was another script that took that code a step further that may help.

> [@Perspective drodown selected label](https://forum.inductiveautomation.com/t/perspective-drodown-selected-label/38723):
>
> I want to get the selected label from a perspective dropdown. This post helped… But, if using showClearIcon and then clearing you will get stale data. Are there any better alternatives to getting the selected label?

---

<div class="post-metadata">

**Author:** ![dwb](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dwb](https://forum.inductiveautomation.com/u/dwb)\
**Post date:** [December 14, 2022, 6:01pm UTC](https://forum.inductiveautomation.com/t/get-selected-text-in-dropdown-component/67612/9 "2022-12-14T18:01:08Z")

</div>

Thank you guys for all your answers, I could do it:  
In the end, this is my script:

```auto
data = self.props.options
	for row in range(data.getRowCount()):
		if (data.getValueAt(row, 0) == self.props.value):
			self.custom.selectedLabel = data.getValueAt(row, 1)
			break

```

Thank you.
