Yogesh Chauhan's Blog

How to select multiple values in React dropdown?

in React on May 16, 2021

Adding a select dropdown in React is quite straightforward.

There are multiple ways do is but let’s go through one way of enabling multi select options.

Let’s try to change the same React select dropdown example and make it accept multiple options value.

The first and foremost thing we need to do is change the select element and make it let use select multiple values.

    <option value="React">React</option>
    <option value="Angular">Angular</option>
    <option value="Vue">Vue</option>

The second thing we need to change is the constructor method and add an array so that we can use that array to store multiple selections from the user.

  this.state = {
    options: ["React"],

After that, we need to change the handleChange method to make it handle the multiple options data.

  handleChange(event) {
    let value = Array.from(
      (option) => option.value
      options: value,

If you’ve a submit button then you need to change the handleSubmit method as well to handle the submitted data.

I have added just an alert to show submitted data to users but it’s up to you how you want to handle the submitted data.

Also, I am using slice method to remove the trailing comma and space since I am appending the strings in for loop.

  handleSubmit(event) {
    let alertTexts = "";
    for (var i = 0; i < this.state.options.length; i++) {
      alertTexts += this.state.options[i] + ", ";
    alertTexts = alertTexts.slice(0, -2); //remove the trailing space and comma
    alert("You selected " + alertTexts);


I have not added any style to it but you can always use CSS to make it look better.

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface #Jan 14 How to display a student’s individual transcript in Colleague? #Jan 11 How to install PuTTY on a MacOS?
You might also like these
What’s new in WordPress 5.5?WordPressHow to add Local State to a Class in React?ReactLearn to make a responsive gallery using CSS Grid and without media queriesCSSHow to create two segues with two UIButtons on a single page (Swift 5.0)?SwiftFew more :nth-child examples in CSSCSSFunction Scope in JavaScript for BeginnersJavaScript