Skip to content

Commit

Permalink
🗃️ Form Handling
Browse files Browse the repository at this point in the history
Form Handling
  • Loading branch information
SaishJ committed Sep 2, 2022
1 parent ac16748 commit 4b36f24
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import PersonList from "./components/PersonList";
import NameList from "./components/NameList";
import StyleSheet from "./components/StyleSheet";
import Inline from "./components/Inline";
import Form from "./components/Form";

function App() {
return (
<div className="App">
<StyleSheet primary={true} />
<Inline />
<Form />
{/* <StyleSheet primary={true} /> */}
{/* <Inline /> */}
{/* <NameList /> */}
{/* <PersonList /> */}
{/* <UserGreeting /> */}
Expand Down
74 changes: 74 additions & 0 deletions src/components/Form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, { Component } from "react";

class Form extends Component {
constructor(props) {
super(props);

this.state = {
username: "",
comments: "",
topic: "React",
};
}

handleUsername = (event) => {
this.setState({
username: event.target.value,
});
};

handleComment = (event) => {
this.setState({
comments: event.target.value,
});
};

handleTopic = (event) => {
this.setState({
topic: event.target.value,
});
};

handleSubmit = (event) => {
alert(
`Username: ${this.state.username}, Comment: ${this.state.comments}, Topic: ${this.state.topic}`
);
event.preventDefault();
};

render() {
return (
<div>
<form onSubmit={this.handleSubmit}>
<div>
<label>Username</label>
<input
type="text"
value={this.state.username}
onChange={this.handleUsername}
/>
</div>
<div>
<label>Comment</label>
<textarea
type="text"
value={this.state.comments}
onChange={this.handleComment}
></textarea>
</div>
<div>
<label>Topic</label>
<select value={this.state.topic} onChange={this.handleTopic}>
<option value="react">React</option>
<option value="angular">Angular</option>
<option value="vue">Vue</option>
</select>
</div>
<button type="submit">Submit</button>
</form>
</div>
);
}
}

export default Form;

0 comments on commit 4b36f24

Please sign in to comment.