---
title: Dynamically Set and Reset Question Values
product: Form Library
description: Automatically populate or reset form fields based on other answers using conditional expressions. View our free JavaScript demo.
framework: jQuery
source: https://surveyjs.io/form-library/examples/set-question-value-dynamically/jquery
index: https://surveyjs.io/form-library/examples/overview.md
---

# Dynamically Set and Reset Question Values (jQuery)

Survey questions support API properties that let you automatically set or reset a question's value based on specific criteria. In this demo, these properties are used to copy the shipping address when a user selects "Yes" for the "Shipping address same as billing" question.

## Set Question Values Dynamically

To set a question's value based on other answers, assign an [expression](/form-library/documentation/design-survey/conditional-logic#expressions) to the [`setValueExpression`](/form-library/documentation/api-reference/question#setValueExpression) property. The result of the expression will be used as the question's value. If you want this expression to be evaluated conditionally, use the [`setValueIf`](/form-library/documentation/api-reference/question#setValueIf) property to specify the condition. This property accepts a Boolean expression, and when it evaluates to `true`, the survey runs the `setValueExpression` and assigns the result to the question's value.

## Reset Question Values Conditionally

To reset a question's value when a certain condition is met, specify the [`resetValueIf`](/form-library/documentation/api-reference/question#resetValueIf) property with a Boolean expression. When this expression evaluates to `true`, the question's value will be reset to the [`defaultValue`](/form-library/documentation/api-reference/question#defaultValue).

Refer to the survey JSON schema (`json.js` file) for code examples.

## 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 $ from "jquery";
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));
});

$("#surveyElement").Survey({ model: survey });
```

### `src/json.js`

```js
export const json = {
  "elements": [
    {
      "type": "comment",
      "name": "billing-address",
      "title": "Billing address",
      "rows": 2
    },
    {
      "type": "boolean",
      "name": "shipping-same-as-billing",
      "title": "Shipping address same as billing",
      "defaultValue": "true"
    },
    {
      "type": "comment",
      "name": "shipping-address",
      "title": "Shipping address",
      "enableIf": "{shipping-same-as-billing} = false",
      "resetValueIf": "{shipping-same-as-billing} = false",
      "setValueIf": "{shipping-same-as-billing} = true",
      "setValueExpression": "{billing-address}",
      "rows": 2
    }
  ],
  "textUpdateMode": "onTyping"
};
```

### `src/theme.js`

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

### `package.json`

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

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/set-question-value-dynamically/angular.md)
- [React](https://surveyjs.io/form-library/examples/set-question-value-dynamically/reactjs.md)
- [Vue 3](https://surveyjs.io/form-library/examples/set-question-value-dynamically/vue3js.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/set-question-value-dynamically/vanillajs.md)
