Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
How to use Bootstrap in React JS ?
Next article icon

How To Get Select Element’s Value In react-bootstrap?

Last Updated : 03 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

React-Bootstrap is a popular library that provides Bootstrap-styled React components. One of the most commonly used form elements is the <select> dropdown, which allows users to choose from a list of options. In this article, we’ll explore how to get the value of a select element in a React-Bootstrap application, and we’ll look at how to handle the value changes efficiently using React’s state management.

Steps To Get Select Element’s Value In react-bootstrap

Step 1: Create a New React Project

npx create-react-app react-gfg cd react-gfg

Step 2: Install React-Bootstrap

npm install react-bootstrap bootstrap

Folder Structure

wdfe

Folder 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.3",
"react": "^18.3.1",
"react-bootstrap": "^2.10.5",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}

Step 3: Include Bootstrap in the Project

In src/index.js, import Bootstrap’s CSS:

JavaScript
//index.js  import 'bootstrap/dist/css/bootstrap.min.css'; import React from 'react'; import ReactDOM from 'react-dom'; import './styles.css';  // optional CSS for extra styling import App from './App';  ReactDOM.render(<App />, document.getElementById('root')); 

Step 4: Create a Dynamic Select Component with Form Submission in App.js

JavaScript
//App.js  import React, { useState } from 'react'; import { Form, Button } from 'react-bootstrap';  function App() {     const [selectedOption, setSelectedOption] = useState('');     const options = ['Option 1', 'Option 2', 'Option 3', 'Option 4'];      const handleSelectChange = (event) => {         setSelectedOption(event.target.value);     };      const handleSubmit = (event) => {         event.preventDefault();         alert(`You selected: ${selectedOption}`);     };      return (         <div className="container mt-5">             <h1>Dynamic Select with Form Submission</h1>             <Form onSubmit={handleSubmit}>                 <Form.Group controlId="dynamicSelect">                     <Form.Label>Select an Option</Form.Label>                     <Form.Control as="select" value={selectedOption} onChange={handleSelectChange}>                         <option value="">Choose...</option>                         {options.map((option, index) => (                             <option key={index} value={option.toLowerCase().replace(' ', '')}>                                 {option}                             </option>                         ))}                     </Form.Control>                 </Form.Group>                 <Button type="submit" variant="primary">Submit</Button>             </Form>             <p className="mt-3">Selected Option: {selectedOption}</p>         </div>     ); }  export default App; 

Step 5: Add Styling (Optional)

In src/App.css, add any custom styles:

CSS
/* App.css */  .container {     max-width: 600px; } 


To start the application run the following command.

npm start

Output

https://media.geeksforgeeks.org/wp-content/uploads/20241003150831/Animation30.mp4


Next Article
How to use Bootstrap in React JS ?

M

manan2000gadwal
Improve
Article Tags :
  • Bootstrap
  • ReactJS
  • Web Technologies
  • Bootstrap-Questions

Similar Reads

  • How to use Multi-Select Dropdown in React-Bootstrap ?
    In ReactJS applications, we always need to add the UI component that allows us to select multiple options from the DropDown list. So in Bootstrap, the Multi-Select Dropdown is a UI component that allows us to select multiple different options from the list of dropdown menus. Additionally, we can do
    4 min read
  • How to get cell value on React-Table ?
    React-Table is a powerful library that allows you to create flexible and feature-rich tables in your React applications. It provides various functionalities to manipulate and interact with table data. One common requirement is to retrieve the value of a specific cell in React-Table. In this article,
    3 min read
  • How to display title in Bootstrap-Select without empty element ?
    In this article, we will cover how to display the title in the Bootstrap-Select without any empty element in the select dropdown menu. Bootstrap Select is a form control that displays a collapsible list of different values that can be selected. This can be used for displaying forms or menus to the u
    2 min read
  • How to get an Element by ID in ReactJS ?
    ReactJS, a popular JavaScript library for user interfaces, empowers developers with tools, such as the ref system, to manipulate the DOM by accessing elements using their unique IDs. This article explores the process of obtaining elements by ID in ReactJS for effective component interaction and mani
    4 min read
  • How to use Bootstrap in React JS ?
    Explore the seamless integration of Bootstrap into React JS for enhanced styling and responsive web development. This comprehensive guide provides step-by-step instructions, covering the installation process, utilization of Bootstrap components, and best practices to harness the power of both techno
    3 min read
  • How to Create Smaller `Input` in React-Bootstrap ?
    ReactJS is one of the most favorite libraries for building attractive applications. Combining Bootstrap with ReactJS is a powerful tool for making the application more interactive. A Smaller Input in React-Bootstrap refers to reducing the size of an input field component, typically achieved by apply
    4 min read
  • How To Set Default Value In Select using ReactJS?
    When building forms in ReactJS, it is common to work with select dropdowns where users can choose an option from a list. Sometimes, you may want to set a default value in the select dropdown to pre-select an option when the form loads. In this article, we’ll explore different approaches to set a def
    3 min read
  • How to Use react-select in React Application?
    React Select is a flexible and handy dropdown library for React that handles multi-select, loading data asynchronously, custom options, and more in your components with ease. In this article, we will see how to use react-select in React Application. PrerequisiteNode.js installednpm or yarn package m
    2 min read
  • How to Get Selected Value in Dropdown List using JavaScript?
    A dropdown list is an HTML element that allows users to select one option from a list of options. The <select> and <option> tags are used to create dropdown lists in HTML. In this article, we will see how to get selected value from dropdown list using JavaScript. Basic HTML Structure for
    3 min read
  • How to Import a Specific Component from React Bootstrap ?
    In this article, we are going to learn about how to import a specific component from React-Bootstrap into your project. React Bootstrap is one of the most popular libraries used for application styling. It has various components embedded in it, which makes the behavior of the application more attrac
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences