Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  28] [ 7]  / answers: 1 / hits: 96734  / 8 Years ago, thu, september 1, 2016, 12:00:00

I want to retrieve the value of my checkbox when it is checked.



I am using this http://react-component.github.io/checkbox/.



My code looks like this.



<div className=user_box>
{ check.map((values , i)=> {
return <Checkbox
name = checkbox
onChange={this.checkvalue.bind(this)}
value={values.username}
/>
})}
</div>


My function:



checkvalue(e){
// var all_users = [];
// var value = this.checkbox.value;
// all_users.push(value);
// console.log(all_users);

console.log('checkbox checked:', (e.target.checked));
}


I'm not understanding how to retrieve the value of the checkbox.


More From » reactjs

 Answers
73

you need to pass the e, Synthetic event parameter to your handler :



handleChange(e) {
let isChecked = e.target.checked;
// do whatever you want with isChecked value
}

render() {
// ... your code here
return (
{/* your other jsx here */}
<Checkbox otherProps onChange={e => this.handleChange(e)} />
{/* your other jsx here */}
);
}

[#60847] Tuesday, August 30, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
loganl

Total Points: 424
Total Questions: 86
Total Answers: 112

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;