Get index of selected dropdown value

I have a list of texts as a field in a type of thing that I’m using to populate a dropdown. I need to set a custom state of element x whenever the dropdown value is changed. The custom state needs to be the index# (or position in list) of the selected value in the dropdown. how do i get the index of a specific item in the list of text or from the dropdown?

Take a look at this Any way to know the numeric position of a specific entry within a list

You will likely need the JS to Bubble or Expression element of the Toolbox plugin for this.

1 Like

How do i go about using expression element of the Toolbox plugin?

Here’s a quick example that may help - https://bubble.io/page?type=page&name=expression_demo&id=louisforum&tab=tabs-1

3 Likes

Thanks! This works perfectly.

1 Like

Hi Louis you’ve been of great help. Do you know how i can have the dropdown value index descend when app is used on a mobile device? Dropdowns seem to populate from last to first (upside-down) when opened on mobile devices (android % IOS) which makes what was last on the list first and changes the indexing accordingly. This defeats the purpose of me using indexes to begin with.

Hi @ntikelo.shingange,

That’s odd. I’d never seen or heard that before. I wonder what, within ios or android, causes that to happen.

Anyway, I think there are plugins that detect what type of device your user is using, so you may be able to set a condition on the expression element for when the user is on an android or ios device. I have updated my example linked above to reverse the index when the screen width is 550px or less, just to show how the expression would look. I hope it helps. I would advise that you use this with caution though - be sure to confirm that it is indeed the device type that causes the index order to be reversed.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.