Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Hide/show dropdown based on selection?

Issue

As a user, I want to hide a dropdown until a specific selection is chosen on another dropdown. I need to find a way to convert the visibility property of the dropdown to JavaScript and add code to only show it if the desired option is selected.

Resolution

To hide a dropdown until a specific selection is chosen on another dropdown, you need to use JavaScript to manipulate the visibility property of the dropdown. First, convert the visibility property of the dropdown to JavaScript by adding {{ }} around it. Next, add the code {{Select1.selectedOptionValue !== undefined}} which checks whether a specific option has been selected in the other dropdown (which is named Select1 in this example).

This code will ensure that the second dropdown is only shown if the specified option has been selected in the first dropdown. You can replace "undefined" with the value of the option that needs to be selected for the second dropdown to be shown. Alternatively, you can use other conditions to determine when the second dropdown should be visible, such as checking for the value of another field.

Here's an example of how this code might look in context:

<select id="Select1">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>

<select id="Select2" style="{{Select1.selectedOptionValue !== undefined ? 'visibility: visible;' : 'visibility: hidden;'}}">
<option value="suboption1">Suboption 1</option>
<option value="suboption2">Suboption 2</option>
</select>

In this example, the second dropdown (Select2) will be invisible by default, but will become visible when the user selects an option in the first dropdown (Select1). This is because the JavaScript code sets the style property of the second dropdown to either "visibility: visible;" or "visibility: hidden;" based on whether the specified option has been selected or not.