Reputation: 419
I am having input tags with radio type
<div className="col-md-12">
<div className="form-group clearfix">
<label htmlFor="" className="col-md-2 control-label">Authentication</label>
<div className="col-md-8">
<input type="radio" name="authentication" value="No Authentication" onChange={this.Authentication.bind(this)} />
No Authentication
<input type="radio" name="authentication" value="Master Credentials" onChange={this.Authentication.bind(this)} />
Master Credentials
</div>
</div>
</div>
And the onChange function
Authentication(e) {
this.setState({ authentication: e.target.value });
}
onChange is getting called only for the first time when i click on second time onChange is not getting called not able to identify what is the problem.
Upvotes: 0
Views: 178
Reputation: 118261
Add checked
props like below:
<div className="col-md-12">
<div className="form-group clearfix">
<label htmlFor="" className="col-md-2 control-label">
Authentication
</label>
<div className="col-md-8">
<input
type="radio"
name="authentication"
value="No Authentication"
checked={this.state.authentication === "No Authentication"}
onChange={this.Authentication.bind(this)}
/>
No Authentication
<input
type="radio"
name="authentication"
value="Master Credentials"
onChange={this.Authentication.bind(this)}
checked={this.state.authentication === "Master Credentials"}
/>
Master Credentials
</div>
</div>
</div>;
Upvotes: 2