---
title: Multiple Textboxes
product: Form Library
description: Multiple Textboxes is a type of question with multiple text input fields, which allows you to group related open-ended questions such as values of a full legal name together. View this free demo example for JavaScript to learn more.
framework: React
source: https://surveyjs.io/form-library/examples/multiple-text-box-question/reactjs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Multiple Textboxes (React)

A Multiple Text Box question contains multiple text entry fields that allow users to enter more than one short text response in a single question. This question type is perfect if you need to collect answers to a group of related open-ended questions without choice options (contact information, full legal name). Built-in input validation allows you to verify input values and make sure they conform with the specified format, such as an email, password, or phone number. This demo shows how to create and add a question with multiple responses to a form and run it in your JavaScript framework.

## Create a Multiple Text Box Question

To create a question with multiple text input fields, define an object with the `type` property set to `"multipletext"` and add it to the [`elements`](https://surveyjs.io/form-library/documentation/api-reference/page-model#elements) array. Use the [`items`](https://surveyjs.io/form-library/documentation/api-reference/multiple-text-entry-question-model#items) array to configure the text input fields. Each object in this array should have at least the following properties:

```js
{
  "name": any, // A unique value used to identify an input item and save an item value to survey results.
  "title": string // An item caption. When `title` is undefined, `name` is used. This property supports Markdown.
}
```

For a full list of available properties, refer to the [`MultipleTextItemModel`](https://surveyjs.io/form-library/documentation/api-reference/multipletextitemmodel) class documentation.

## Specify Input Type

If an input field requires specific values, use the [`inputType`](https://surveyjs.io/form-library/documentation/questiontextmodel#inputType) property to specify the input type. An `inputType` value is passed on to the [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#input_types) attribute of the underlying `<input>` HTML element. This example demonstrates the `"number"`, `"email"`, `"password"`, and the default `"text"` input types.

## Validate Input Values

If you need to ensure that respondents fill out all required form fields and the format of values is correct, enable data validation. This example demonstrates the following validation types and describes how to configure them:

- Required Validation           
Enable the [`isRequired`](https://surveyjs.io/form-library/documentation/questiontextmodel#isRequired) property for the form fields that should not be empty.

- Number Range Validation            
Define an object with the `type` property set to `"numeric"` and add it to the [`validators`](https://surveyjs.io/form-library/documentation/questiontextmodel#validators) array. Use the [`minValue`](https://surveyjs.io/form-library/documentation/numericvalidator#minValue) and [`maxValue`](https://surveyjs.io/form-library/documentation/numericvalidator#maxValue) properties within this object to specify the range. Alternatively, you can use the [`min`](https://surveyjs.io/form-library/documentation/questiontextmodel#min) and [`max`](https://surveyjs.io/form-library/documentation/questiontextmodel#max) properties in the question object.

- Expression Validation           
Define an object with the `type` property set to `"expression"` and add it to the `validators` array. Assign a [Boolean expression](https://surveyjs.io/form-library/documentation/design-survey/conditional-logic#conditional-visibility) to the [`expression`](https://surveyjs.io/form-library/documentation/api-reference/expressionvalidator#expression) property within this object (see the "Highest price" form field in this demo).

- RegEx Validation          
Define an object with the `type` property set to `"regex"` and add it to the `validators` array. Assign a regular expression to the [`regex`](https://surveyjs.io/form-library/documentation/regexvalidator#regex) property within this object (see the Password form field in this demo).

To learn more about data validation in SurveyJS Form Library, refer to the following help topic: [Data Validation](https://surveyjs.io/form-library/documentation/data-validation).

## Access Input Values

A Multiple Text Box question adds an object with the structure described below to survey results:

```js
{
  "multipleTextBoxQuestionName": { // Question name
    // Individual text field values
    "item1Name": "item1Value",
    "item2Name": "item2Value",
    // ...
    "itemNName": "itemNValue"
  }
}
```

Refer to the following help topic for information on how to access individual item values in JavaScript code: [Access Survey Results](https://surveyjs.io/form-library/documentation/handle-survey-results-access).

If you want to reference an item in expressions, use the following notation: `{questionname.itemname}`. For more information about expression syntax, refer to the [Conditional Logic and Dynamic Texts](https://surveyjs.io/form-library/documentation/design-survey/conditional-logic) documentation article.

## Files

### `public/index.html`

```html
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
<div id="surveyElement" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; min-height: 100%; height:100%"></div>
```

### `src/SurveyComponent.jsx`

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

function SurveyComponent() {
    const survey = new Model(json);
    survey.onComplete.add((sender, options) => {
        console.log(JSON.stringify(sender.data, null, 3));
    });
    survey.onTextMarkdown.add((_, options) => {
        // Convert Markdown to HTML
        let str = marked(options.text);
        // Remove root paragraphs <p></p>
        str = str.substring(3);
        str = str.substring(0, str.length - 5);
        // Set HTML markup to render
        options.html = str;
    });
    
    return (<Survey model={survey} />);
}

export default SurveyComponent;
```

### `src/index.css`

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

### `src/index.js`

```js
import React from "react";
import { createRoot } from "react-dom/client";
import SurveyComponent from "./SurveyComponent";

const root = createRoot(document.getElementById("surveyElement"));
root.render(<SurveyComponent />);
```

### `src/json.js`

```js
export const json = {
  "checkErrorsMode": "onValueChanged",
  "elements": [
    {
      "type": "multipletext",
      "name": "pricelimit",
      "title": "How much would you be willing to pay for a product like ours?",
      "isRequired": true,
      "items": [
        {
          "name": "mostamount",
          "title": "Highest price",
          "inputType": "number",
          "validators": [{
            "type": "expression",
            "expression": "{pricelimit.mostamount} empty or {pricelimit.leastamount} empty or {pricelimit.mostamount} >= {pricelimit.leastamount}",
            "text": "The highest price must be higher than the lowest price."
          }, {
            "type": "numeric",
            "minValue": 0,
            "text": "Price cannot be less than zero."
          }]
        },
        {
          "name": "leastamount",
          "title": "Lowest price",
          "inputType": "number",
          "validators": [{
            "type": "numeric",
            "minValue": 0,
            "text": "Price cannot be less than zero."
          }]
        }
      ]
    },
    {
      "type": "multipletext",
      "name": "register",
      "title": "Register Form",
      "items": [
        {
          "name": "username",
          "isRequired": true,
          "title": "<i class='fa fa-user icon'></i> Username",
          "maxLength": 20
        },
        {
          "name": "email",
          "title": "<i class='fa fa-envelope icon'></i> Email",
          "inputType": "email"
        },
        {
          "name": "password",
          "title": "<i class='fa fa-key icon'></i> Password",
          "inputType": "password",
          "validators": [
            {
              "type": "regex",
              "text": "Your password must be at least 8 characters long and contain at least one letter and one number.",
              "regex": "^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$"
            }
          ]
        }
      ]
    }
  ]
};
```

### `src/theme.js`

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

### `package.json`

```json
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "marked": "latest",
    "survey-core": "latest",
    "survey-react-ui": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/multiple-text-box-question/angular.md)
- [Vue 3](https://surveyjs.io/form-library/examples/multiple-text-box-question/vue3js.md)
- [jQuery](https://surveyjs.io/form-library/examples/multiple-text-box-question/jquery.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/multiple-text-box-question/vanillajs.md)
