# Using drop down as a conditional for an if statement

**URL:** <https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657>\
**Category:** Ignition\
**Created:** [May 3, 2019, 7:21pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657 "2019-05-03T19:21:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ethanrendlen](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ethanrendlen](https://forum.inductiveautomation.com/u/ethanrendlen)\
**Post date:** [May 3, 2019, 7:21pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657/1 "2019-05-03T19:21:04Z")

</div>

Hello,  
See this picture of the drop down:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/567644ba3f71ef9daf5418044d4d4a2747f0cf51.png)

My code is:

if event.source.parent.getComponent(‘Dropdown’).selectedStringValue == “Labeling” :

#The event is not triggered as it should be, I have some logic that runs properly with no if statement, I seem to be running into the problem at this point. The if statement is not returning true even though I believe it is true.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [May 3, 2019, 7:49pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657/2 "2019-05-03T19:49:53Z")

</div>

Do you have “Labeling” for both the value _and_ the display label (ie both columns in your dataset)? If not, try changing your script to use .selectedLabel

---

<div class="post-metadata">

**Author:** ![Paul.Scott](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul.scott/32/4578_2.png) [@Paul.Scott](https://forum.inductiveautomation.com/u/Paul.Scott)\
**Post date:** [May 3, 2019, 10:00pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657/3 "2019-05-03T22:00:06Z")

</div>

![567644ba3f71ef9daf5418044d4d4a2747f0cf51](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4c04e3df36a82ee1048a12b5cf6023fa97ba32cb.png)

I can’t help but notice the ellipses at the end. It looks like the text in your dropdown is being truncated. Is there a lot of trailing space at the end of `Labeling`? If so, then the string comparison is going to fail unless you’re including the trailing spaces.

---

<div class="post-metadata">

**Author:** ![ethanrendlen](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ethanrendlen](https://forum.inductiveautomation.com/u/ethanrendlen)\
**Post date:** [May 6, 2019, 2:40pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657/4 "2019-05-06T14:40:36Z")

</div>

Thank you but unfortunately there is no space after the word labeling. I am the one who filled out the data for inside the drop down. It reflects a custom entry in a SQL table. “Labeling” as a string should be the only thing there. There are some longer items on the drop down that need the ellipses, and it looks like Ignition might put them there.  
Even if the box is longer the ellipses are there.

---

<div class="post-metadata">

**Author:** ![ethanrendlen](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ethanrendlen](https://forum.inductiveautomation.com/u/ethanrendlen)\
**Post date:** [May 6, 2019, 2:41pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657/5 "2019-05-06T14:41:23Z")

</div>

I have tried using both of those values (.selectedString and .selectedLabel) and my label is also the same on top of that. 😕

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [May 6, 2019, 3:04pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657/6 "2019-05-06T15:04:50Z")

</div>

What is the field type in the database table?

---

<div class="post-metadata">

**Author:** ![ethanrendlen](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ethanrendlen](https://forum.inductiveautomation.com/u/ethanrendlen)\
**Post date:** [May 6, 2019, 3:06pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657/7 "2019-05-06T15:06:37Z")

</div>

Ahhh… It is nchar(50), maybe nvarchar(50) would help?

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [May 6, 2019, 3:07pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657/8 "2019-05-06T15:07:51Z")

</div>

Yes and that alludes to Pauls response.  
nchar(50) will append spaces to the end of the actual text to fill to 50 characters.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [May 6, 2019, 4:50pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657/9 "2019-05-06T16:50:09Z")

</div>

Or just trim the whitespace off the string before the comparison if you don’t want to change the datatype. (I think strip() does that?)

---

<div class="post-metadata">

**Author:** ![ethanrendlen](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ethanrendlen](https://forum.inductiveautomation.com/u/ethanrendlen)\
**Post date:** [May 6, 2019, 5:38pm UTC](https://forum.inductiveautomation.com/t/using-drop-down-as-a-conditional-for-an-if-statement/24657/10 "2019-05-06T17:38:14Z")

</div>

Thanks for the input Kathy, that is an interesting point.
