Selected Index not Working Correctly

Hello Everyone,

So I have a dropdown change event that will populate a text box with a number and what number that will be is determined by the selection made by the drop down. I have done something similar to this, just stuck and don’t know how to fix this.

export function dropdown1_change(event) {
let selectedIndex = $w( “#dropdown1” ).selectedIndex;
if (selectedIndex === 1){
$w( “#text1” ).text =(100).toFixed( 2 ).toString();
} if (selectedIndex === 2) {
$w( “#text1” ).text =(200).toFixed( 2 ).toString();
} if (selectedIndex === 3) {
$w( “#text1” ).text =(300).toFixed( 2 ).toString();
} if (selectedIndex === 4) {
$w( “#text1” ).text =(400).toFixed( 2 ).toString();
} if (selectedIndex === 5) {
$w( “#text1” ).text =(500).toFixed( 2 ).toString();
}
}

Any help would be greatly appreciated.

The index starts from zero.

@jonatandor35 Hey J.D.

Can you elaborate more please?

@bensmitth the first value has index 0, the second has index 1, the third - index 2.

It should be something like:

const selectedIndex = $w("#dropdown1").selectedIndex;
$w("#text1").text = ((selectedIndex  + 1) * 100).toFixed(2);

and without .toString() as .toFixed() already converted it to string.