I have few radio buttons in my form. When I check the radio buttons I try to log them in console but now I want to get the text of radio button and save it in a state variable but I am not able to store it in state variable. There are 4 options in question 1 of the form eg: >=25 yrs, 26-35yrs,etc I want to store these age in state variable.
contactform.js :
import React, { Component } from 'react';
class ContactForm extends Component {
constructor(props){
super(props);
this.state = {
age:'',
gender:'',
health:'',
name:'',
email:'',
info:'',
fitness:''
};
}
setAge(checkedValue){
console.log(checkedValue);
if(checkedValue === '-1'){
console.log(this.state.age)
}
}
render() {
return (
<div>
<div id="center">
<form>
<div className="form-group">
<div className="col-sm-offset-2 col-sm-10">
<h3>[Test]Contact us Survey Form</h3>
</div>
</div>
<div id="agegroup" >
<div className="form-group">
<div className="col-sm-offset-2 col-sm-10">
<h4>What is your age group?</h4>
</div>
</div>
<div className="form-group">
<div className="col-sm-offset-2 col-sm-10">
<div className="radio">
<label><input type="radio" name="age" onChange={this.setAge.bind(this,'>=25 yrs')}/> >=25 yrs</label>
</div>
</div>
</div>
<div className="form-group">
<div className="col-sm-offset-2 col-sm-10">
<div className="radio">
<label><input type="radio" name="age" onChange={this.setAge.bind(this,'26-35 yrs')}/> 26-35 yrs</label>
</div>
</div>
</div>
<div className="form-group">
<div className="col-sm-offset-2 col-sm-10">
<div className="radio">
<label><input type="radio" name="age" onChange={this.setAge.bind(this,'36-50 yrs')}/> 36-50 yrs</label>
</div>
</div>
</div>
<div className="form-group">
<div className="col-sm-offset-2 col-sm-10">
<div className="radio">
<label><input type="radio" name="age" onChange={this.setAge.bind(this,'>50 yrs')}/> >50 yrs</label>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
);
}
}
export default ContactForm;
Screenshot of my form:

setAgefunction defined??age.Like should it be36-50 yrs?