---
title: Conditionally Display Choice Options
product: Form Library
description: Make sure respondents only see choice options relevant to them. Use the visibleIf property to make choice options visible or invisible based on preconfigured conditions. View our free JavaScript demo to learn more.
framework: Vanilla JS
source: https://surveyjs.io/form-library/examples/how-to-conditionally-display-choice-options/vanillajs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Conditionally Display Choice Options (Vanilla JS)

Multiple-choice questions, such as [Checkboxes](/form-library/examples/create-checkboxes-question-in-javascript/) or [Radio Button Group](/form-library/examples/single-select-radio-button-group/), allow you to show and hide choice options conditionally. The configuration object of each choice option supports a `visibleIf` property that accepts a Boolean expression. Each time this expression evaluates to `true`, the choice option becomes visible. In this demo, you can provide an email address, phone number, or Telegram nickname, and the survey will prompt you to select your preferred contact option. The `visibleIf` property is used to display a contact option only if a user has provided it.

As an alternative, you can use a question's [`choicesVisibleIf`](https://surveyjs.io/form-library/documentation/api-reference/checkbox-question-model#choicesVisibleIf) property. This property also accepts a Boolean expression, but the expression is evaluated for each choice option individually to determine its visibility. For more information, refer to the following help topic:

[Conditional Visibility](https://surveyjs.io/form-library/documentation/design-survey/conditional-logic#conditional-visibility (linkStyle))

## Files

### `public/index.html`

```html
<div id="surveyElement" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; min-height: 100%; height:100%"></div>
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/index.js`

```js
import { Model } from "survey-core";
import "survey-js-ui";
import "survey-core/survey-core.min.css";
import "./index.css";
import { json } from "./json";

const survey = new Model(json);
survey.onComplete.add((sender, options) => {
    console.log(JSON.stringify(sender.data, null, 3));
});

survey.render(document.getElementById("surveyElement"));
```

### `src/json.js`

```js
export const json = {
  "elements": [
    {
      "type": "panel",
      "name": "contact-information",
      "title": "Contact Information",
      "questionTitleWidth": "100px",
      "questionTitleLocation": "left",
      "elements": [
        {
          "type": "text",
          "name": "email",
          "title": "Email",
          "inputType": "email"
        },
        {
          "type": "text",
          "name": "phone",
          "title": "Phone",
          "inputType": "tel"
        },
        {
          "type": "text",
          "name": "telegram",
          "title": "Telegram"
        }
      ]
    },
    {
      "type": "checkbox",
      "name": "contactby",
      "title": "How we may contact you?",
      "visibleIf": "{email} notempty or {phone} notempty or {telegram} notempty",
      "choices": [
        {
          "value": "email",
          "text": "By email",
          "visibleIf": "{email} notempty"
        },
        {
          "value": "phone_call",
          "text": "By a phone call",
          "visibleIf": "{phone} notempty"
        },
        {
          "value": "sms",
          "text": "By SMS",
          "visibleIf": "{phone} notempty"
        },
        {
          "value": "telegram",
          "text": "By Telegram",
          "visibleIf": "{telegram} notempty"
        }
      ]
    }
  ]
};
```

### `src/theme.js`

```js
export const themeJson = {};
```

### `package.json`

```json
{
  "dependencies": {
    "survey-core": "latest",
    "survey-js-ui": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/how-to-conditionally-display-choice-options/angular.md)
- [React](https://surveyjs.io/form-library/examples/how-to-conditionally-display-choice-options/reactjs.md)
- [Vue 3](https://surveyjs.io/form-library/examples/how-to-conditionally-display-choice-options/vue3js.md)
- [jQuery](https://surveyjs.io/form-library/examples/how-to-conditionally-display-choice-options/jquery.md)
