screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; function App() { const [formData, setFormData] = useState({ name: '', email: '', gender: '', }); const handleInputChange = (e) => { const { name, value } = e.target; setFormData({ ...formData, [name]: value, }); }; return ( <div className='container'> <h3>React js Handle Input Change</h3> <input type="text" name="name" value={formData.name} onChange={handleInputChange} placeholder="Name" /> <input type="email" name="email" value={formData.email} onChange={handleInputChange} placeholder="Email" /> <select name="gender" value={formData.gender} onChange={handleInputChange} > <option value="">Select Gender</option> <option value="male">Male</option> <option value="female">Female</option> <option value="other">Other</option> </select> <p>Name: {formData.name}</p> <p>Email: {formData.email}</p> <p>Gender: {formData.gender}</p> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Container */ .container { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); text-align: center; } h3 { color: #333; } form { display: flex; flex-direction: column; align-items: center; } label { font-weight: bold; } select[name="gender"] { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px; outline: none; cursor: pointer; } input[type="text"], input[type="email"] { width: 100%; padding: 10px; margin: 5px 0; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; box-sizing: border-box; } </style> </body> </html>