# Conditional input widget

**URL:** <https://talk.observablehq.com/t/conditional-input-widget/8646>\
**Category:** Help\
**Created:** [December 25, 2023, 1:54pm UTC](https://talk.observablehq.com/t/conditional-input-widget/8646 "2023-12-25T13:54:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mindlessgreen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mindlessgreen/32/8402_2.png) [@mindlessgreen](https://talk.observablehq.com/u/mindlessgreen)\
**Post date:** [December 25, 2023, 1:54pm UTC](https://talk.observablehq.com/t/conditional-input-widget/8646/1 "2023-12-25T13:54:44Z")

</div>

I have an input

```auto
viewof choice = Inputs.select(["Selection", "Text"], {label: "Input type", multiple: false})

```

I want a different widget to be displayed depending on that input.

```auto
{
  if (choice === "Selection") {
    viewof text = Inputs.select(["A","B"], {label: "Select text"});
  } else if (choice === "Text") {
    viewof text = Inputs.textarea({label: "Enter text", value: "Dummy text"});
  }
}

```

```auto
${text}

```

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [December 25, 2023, 5:22pm UTC](https://talk.observablehq.com/t/conditional-input-widget/8646/2 "2023-12-25T17:22:55Z")

</div>

`viewof` and the cell name can only be declared at the start of a cell:

```auto
viewof text = {
  if (choice === "Selection") {
    return Inputs.select(["A","B"], {label: "Select text"});
  } else if (choice === "Text") {
    return Inputs.textarea({label: "Enter text", value: "Dummy text"});
  }
}
```
