screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script> <script crossorigin src="https://unpkg.com/react-dom@18/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({ firstName: '', lastName: '', email: '', }); const handleChange = (event) => { const { name, value } = event.target; setFormData({ ...formData, [name]: value, }); }; const handleSubmit = (event) => { event.preventDefault(); // You can perform form submission and validation logic here alert(`Submitted Data:\n\nFirst Name: ${formData.firstName}\nLast Name: ${formData.lastName}\nEmail: ${formData.email}`); }; return ( <div className='container'> <h3> React Js Handling Multiple Inputs with a Single onChange Handler</h3> <form onSubmit={handleSubmit}> <input type="text" name="firstName" value={formData.firstName} onChange={handleChange} placeholder="First Name" /> <input type="text" name="lastName" value={formData.lastName} onChange={handleChange} placeholder="Last Name" /> <input type="email" name="email" value={formData.email} onChange={handleChange} placeholder="Email" /> <button type="submit">Submit</button> </form> </div> ); } const root = ReactDOM.createRoot(document.getElementById('app')); root.render(<App />); </script> <style> /* Styling for the container */ .container { max-width: 800px; margin: 0 auto; padding: 20px; font-family: Arial, sans-serif; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); } form { display: flex; flex-direction: column; } input { margin-bottom: 16px; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; } button { padding: 12px 20px; border: none; border-radius: 4px; background-color: #007bff; color: #fff; font-size: 18px; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #0056b3; } </style> </body> </html>