screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <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 App = () => { const resetForm = (event) => { event.preventDefault(); alert("Successfully Submitted"); event.target.reset(); }; return ( <div className="container"> <h3>React Js Reset form fields after submit</h3> <form id="form" onSubmit={resetForm}> <input type="text" name="name" placeholder="Enter Name" /> <input type="email" name="email" placeholder="Enter E-mail" /> <textarea name="address" placeholder="Enter Address"></textarea> <button type="submit">Submit</button> </form> </div> ); }; ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { max-width: 400px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .container h3 { font-size: 24px; margin-bottom: 20px; } #form input[type="text"], #form input[type="email"], #form textarea { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box; } #form button[type="submit"] { display: block; width: 100%; padding: 10px; background-color: #4caf50; color: white; border: none; border-radius: 5px; cursor: pointer; } #form button[type="submit"]:hover { background-color: #45a049; } #form input[type="text"]:focus, #form input[type="email"]:focus, #form textarea:focus { outline: none; border-color: #4caf50; } </style> </body> </html>