<input type="checkbox" onclick="onClickHandler()" onchange="onChangeHandler()" />
From within onClickHandler
and/or onChangeHandler
, how can I determine what is the new state of the checkbox?
This question is related to
javascript
html
events
dom
checkbox
Use this
<input type="checkbox" onclick="onClickHandler()" id="box" />
<script>
function onClickHandler(){
var chk=document.getElementById("box").value;
//use this value
}
</script>
For React.js, you can do this with more readable code. Hope it helps.
handleCheckboxChange(e) {
console.log('value of checkbox : ', e.target.checked);
}
render() {
return <input type="checkbox" onChange={this.handleCheckboxChange.bind(this)} />
}
Source: Stackoverflow.com