Get index of selected item in drop list?

Is there a way to do this? Or can we use values in drop lists at all?

I have a really long drop list so i don’t want to do if selected = ‘my string’ or … x50 times.

Could i use this javascript?

document.getElementById("mySelect").selectedIndex

Any help appreciated!

I guess it depends on what you need, but when the user selects an option, you could set a global variable to the text of the selected option, and then do something with that variable.

Hi v3nt,

Going off mnearents’ suggestion, you can set a variable to the selected item from the Droplist. So you can add something like this to the Droplist’s OnSelectionChange event:

“Set value of [index] equal to selected option of This”

This will store the text of the selected item to the “index” variable, which you can then use in the pertaining case(s) to call on that selected value.

I’ve attached a simple example file to demonstrate this. Hope it helps! :slight_smile:
DroplistSelection.rp (59.8 KB)

thanks for the responses guys but that’s not what i want.

I have a list with 50 options. I just want to know if the users clicked an option from the first 25 or the last 25. Index of would do this for me and would save 50 ‘if value = xyz’ …

You can get the value with a little javascript/jquery.
selectAddRemoveDisableEnableCountOption.rp (72.9 KB)

1 Like

Is there any sort of pattern to your options? If there’s something the first 25 all have in common and something different the last 25 all have in common, there could be an option with only 1 or 2 conditions.

Hypothetically, if first 25 all started with ‘$’ while the last 25 all started with ‘#’ you could test the first character of the selected item and branch your logic there. No need for tons of cases or conditions.

Thanks, @Gregor !
That looks like exactly what the OP requested, and it’s also what I happen to be looking for.
(Also, including all those buttons really helps with learning how it works.)

It’s nice to not have to implement a whole repeater if all you need to do is tack a few new (user-entered) values onto a droplist. Likewise, it’s nice to be able to ignore any user-entered value for other purposes, based on its index.