Linking a drop down menu to text

Is there a way to link a drop down menu to text?

Hey
Please explain more details or add screenshot so we understand better and can assist you.

Hi,
Do you refer to a dropdown user input or the menu element added from the editor? Can you please send us a screenshot so that we can better understand what you are trying to achieve?

Thanks,
Tal.

Yes User input I’m trying to select a quantity to show a price. Also the price would change with the quantity selected.

Hi,
You should create an onChange event for the dropdown and check the selected index to perform the action you wish to perform. Here’s a code example to clarify:

$w("#dropdown").onChange( (event, $w) => { 
   if($w("#myDropdown").selectedIndex === 0){
      //perform the change of the first item selected
   } 
    if($w("#myDropdown").selectedIndex === 1){ 
    //perform the change of the second item selected 
    }   
});

You can read more about the dropdown documentation here.

Best,
Tal.

1 Like

I know this post is old, but the code is incomplete, and there is an additional syntax error. First the syntax error: the item identified doesn’t match all uses. After that, you need to declare a new variable and then use that new variable in the “if” statement. Here is your code with the fixes:

$w("#myDropdown").onChange((event, $w)=>{ 
   let dropdownSelection = $w("#myDropdown").selectedIndex;
   if(dropdownSelection) === 0){
      //perform change for selection 1
   } 
   if(dropdownSelection) === 1){
      //perform change for selection 2
   }   
});

Good luck to those who stumble across this. . .