screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Load Existing Database Record to React.js Form</title> <script src="https://unpkg.com/react@17.0.2/umd/react.production.min.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js"></script> <script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; const App = () => { const [selectedValue, setSelectedValue] = useState(''); // Your array of country and state options const options = [ { label: 'California, USA', value: 'california_usa' }, { label: 'New York, USA', value: 'new_york_usa' }, { label: 'Ontario, Canada', value: 'ontario_canada' }, // Add more options as needed ]; // Function to handle the selection change const handleSelectChange = (event) => { setSelectedValue(event.target.value); }; return ( <div className='container'> <h3>React Js Get Selected Value from a Mapped Select Input </h3> <select value={selectedValue} onChange={handleSelectChange}> <option value="">Select an option</option> {options.map((option) => ( <option key={option.value} value={option.value}> {option.label} </option> ))} </select> <p> {selectedValue}</p> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Styles for the container and button */ .container { max-width: 500px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; align-items: center; justify-content: center; } /* Styling for the select element */ .container select { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; outline: none; } /* Styling for the option elements */ .container option { font-size: 16px; } /* Styling for the paragraph */ .container p { font-size: 16px; color: #333; margin: 0; } /* Styling for the selected value */ .container p::before { content: "Selected Value: "; font-weight: bold; } </style> </body> </html>