-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactRadioButton.js
72 lines (51 loc) · 1.52 KB
/
reactRadioButton.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 2020, 7/11, am 7:35 - 8:10 (duration: 35 mins)
// UI: form within redio button
// Controlled by React
// radio button is a input of radio type
// checked: it matters with data of bool type
var React = require("react");
var KsForm = React.createClass({
getInitialState: function(){
return {
radioButtonVal: "Black Coffee"
};
},
changeHandler: function(event){
this.setState(
{radioButton: event.target.value}
);
},
formSubmitter: function(param){
param.preventDefault()
alert(this.state.radioButtonVal);
},
render: function(){
return <form onSubmit={this.formSubmitter}>
<input type="radio"
value="Red Tea"
checked={this.state.radioButtonVal="Red Tea"}
onChange={this.changeHandler}
>
Red Tea
</input>
<br/>
<input type="radio"
value="Black Coffee"
checked={this.state.radioButtonVal="Black Coffee"}
onChange={this.changeHandler}
>
Black Coffee
</input>
<br/>
<input type="radio"
value="Distilled Water"
checked={this.state.radioButtonVal="Distilled Water"}
onChange={this.changeHandler}
>
Distilled Water
</input>
<br/>
<button type="submit"> OK! plz send it out. </button>
</form>
}
});