Open In App

How To Get Multiple Checkbox Values In ReactJS?

Last Updated : 09 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
News Follow

Handling checkboxes in ReactJS becomes important when creating forms or managing user input. If you need to select multiple options, we can do it by implementing multiple checkboxes. In this article, we’ll explore how to get the values of multiple checkboxes in ReactJS, manage the state, and display the selected values.

Prerequisites

Approach

To Get Multiple Checkbox Values In ReactJS we will create a simple form that asks the user to select the programming languages they are familiar with. To get multiple checkbox values in ReactJS we will use the HTML DOM checkbox input and store the data accordingly. Handling multiple checkbox values is a common requirement in forms.

Steps To Create React Application

Step 1: Initialize the React project using this command.

npx create-react-app form-check
cd form-check

Step 2: Use this command to install bootstrap

npm  i bootstrap

Project Structure

The default project structure 

Dependencies

"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.3.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}

Example: This example uses HTML checkbox for multiple checkbox input and bootstrap for styling the form and displaing user choices..

CSS
/* Filename - App.css */

.text {
    width: 50%;
    margin: auto;
}

.top {
    /* margin: auto; */
    margin-top: 4%;
    width: 50%;
    border: 2px ridge black;
    background-color: #f1f1f1;
}

h3 {
    text-align: center;
}

.row {
    padding-left: 20%;
}
JavaScript


Step to run the application: Run our application by using the following command:

npm start 

Output: By default, the React project will run on port 3000. You can access it at localhost:3000 on your browser.

Get Multiple Checkbox Values In ReactJS



Next Article

Similar Reads

three90RightbarBannerImg