screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <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 [contactMethod, setContactMethod] = useState(''); const [email, setEmail] = useState(''); const [phone, setPhone] = useState(''); const handleContactChange = (event) => { setContactMethod(event.target.value); }; const handleEmailChange = (event) => { setEmail(event.target.value); }; const handlePhoneChange = (event) => { setPhone(event.target.value); }; return ( <div className='container'> <h1>React Js Show or hide input fields based on select value</h1> <h2>Contact Information</h2> <label> Preferred Contact Method: <select value={contactMethod} onChange={handleContactChange}> <option value="">Select an option</option> <option value="email">Email</option> <option value="phone">Phone</option> <option value="none">None</option> </select> </label> {contactMethod === 'email' && ( <label> Email: <input type="email" value={email} onChange={handleEmailChange} /> </label> )} {contactMethod === 'phone' && ( <label> Phone: <input type="tel" value={phone} onChange={handlePhoneChange} /> </label> )} </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Styles for the container and button */ .container { max-width: 800px; 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 */ select, input[type="email"], input[type="tel"] { 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; } label { display: block; margin-bottom: 10px; } </style> </body> </html>