# Generate a List of Select Input Label & Value Dynamically

**URL:** <https://community.weweb.io/t/generate-a-list-of-select-input-label-value-dynamically/3724>\
**Category:** How do I?\
**Tags:** design\
**Created:** [July 31, 2023, 11:22am UTC](https://community.weweb.io/t/generate-a-list-of-select-input-label-value-dynamically/3724 "2023-07-31T11:22:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrHariri](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/drhariri/32/517_2.png) [@DrHariri](https://community.weweb.io/u/DrHariri)\
**Post date:** [July 31, 2023, 11:22am UTC](https://community.weweb.io/t/generate-a-list-of-select-input-label-value-dynamically/3724/1 "2023-07-31T11:22:44Z")

</div>

Hello,  
I have a select input that I wanted to generate & control with logic because I want to show 3 options in one case (user has certain plan) and 2 options in another case.

I didn’t want to rely on DB/Backend to generate the options and at the same time the manual list didn’t offer me a way to show/hide options. Therefore, I used the following code which I hope you can find helpful if you want to control your options based on logic and not have to duplicate the input select.

```auto
// Define the condition
let condition = true; // Replace with your actual condition

// Define the two different lists
let list1 = [
  { label: 'BuyTest Label here', value: 'BuyTest' },
  { label: 'Buy Label here', value: 'Buy' },
  { label: 'Sales Label here', value: 'Sales' },
];

let list2 = [
  { label: 'BuyTest Label here', value: 'BuyTest' },
  { label: 'Sales Label here', value: 'Sales' },
];

// Use the condition to determine which list to return
return condition ? list1 : list2;

```

---

<div class="post-metadata">

**Author:** ![DrHariri](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/drhariri/32/517_2.png) [@DrHariri](https://community.weweb.io/u/DrHariri)\
**Post date:** [July 31, 2023, 1:39pm UTC](https://community.weweb.io/t/generate-a-list-of-select-input-label-value-dynamically/3724/2 "2023-07-31T13:39:08Z")

</div>

Here is an updated version showing an example function that would determine the condition:

```auto
// Access the global variable
const planFeatures = pluginVariables['f5856798-485d-47be-b433-d43d771c64e1']['user']?._user_subscription?._plan_features;

// Search for the object where key="feature_key" and value="enable_exp_buy_intent"
const feature = planFeatures.find(feature => feature.feature_key === "enable_exp_buy_intent");

// Return true if value is 1, otherwise return false
const condition = feature ? feature.value === 1 : false;

// Define the two different lists
let list1 = [
  { label: 'Your Label', value: 'BuyTest' },
  { label: 'Your Label', value: 'Buy' },
  { label: 'Your Label', value: 'Sales' },
];
let list2 = [
  { label: 'BuyTest Label here', value: 'BuyTest' },
  { label: 'Sales Label here', value: 'Sales' },
];

// Use the condition to determine which list to return
// First is run if condition = true
return condition ? list1 : list2;

```
