screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.14.0/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.14.0/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 [selectedOption, setSelectedOption] = useState(null); const handleRadioChange = (event) => { setSelectedOption(event.target.value); }; return ( <div className="container"> <h3>React Js Enable Disable Input Field based on Radio Button Selection </h3> <div className="row"> <input className="radio-input" value="one" name="stars" type="radio" checked={selectedOption === "one"} onChange={handleRadioChange} /> <input className="number-input" type="number" disabled={selectedOption !== "one"} /> </div> <div className="row"> <input className="radio-input" value="two" name="stars" type="radio" checked={selectedOption === "two"} onChange={handleRadioChange} /> <input className="number-input" type="number" disabled={selectedOption !== "two"} /> </div> <div className="row"> <input className="radio-input" value="three" name="stars" type="radio" checked={selectedOption === "three"} onChange={handleRadioChange} /> <input className="number-input" type="number" disabled={selectedOption !== "three"} /> </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { margin: 0 auto; width: 500px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; display: flex; flex-direction: column; align-items: center; } .row { display: flex; align-items: center; margin-bottom: 10px; } .radio-input { margin-right: 10px; } .number-input { padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; } .number-input:disabled { background-color: #f5f5f5; color: #999; } </style> </body> </html>