-
Notifications
You must be signed in to change notification settings - Fork 4
/
Forms.jsx
39 lines (32 loc) · 1.18 KB
/
Forms.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React from 'react';
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = { value: '', fruit: null };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({ value: event.target.value });
}
handleSubmit(event) {
alert('A name was submitted: ' + this.state.value);
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
Favourite Food:
<select value={this.state.fruit} onChange={select => this.setState({fruit: select.target.value})}>
<option value="grapefruit">Grapefruit</option>
<option value="lime">Lime</option>
<option value="coconut">Coconut</option>
<option value="mango">Mango</option>
</select>
<input type="submit" value="Submit" />
</form>
);
}
}