JavaScript/jQuery CheckBox - Handle the Value Change Event

To process a new CheckBox value, you need to handle the value change event. If the handling function is not going to be changed during the lifetime of the UI component, assign it to the onValueChanged property when you configure the UI component.

jQuery
JavaScript
$(function() {
    $("#checkBoxContainer").dxCheckBox({
        onValueChanged: function (e) {
            const previousValue = e.previousValue;
            const newValue = e.value;
            // Event handling commands go here
        }
    });
});
Angular
HTML
TypeScript
<dx-check-box
    [(value)]="checkBox_value"
    (onValueChanged)="handleValueChange($event)">
</dx-check-box>
import { DxCheckBoxModule } from "devextreme-angular";
// ...
export class AppComponent {
    checkBox_value = undefined;

    handleValueChange (e) {
        const previousValue = e.previousValue;
        const newValue = e.value;
        // Event handling commands go here
    }
}
@NgModule({
    imports: [
        // ...
        DxCheckBoxModule
    ],
    // ...
})
Vue
App.vue
<template>
    <DxCheckBox
        v-model:value="checkBox_value"
        @value-changed="handleValueChange"
    />
</template>

<script>
import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.css';

import DxCheckBox from 'devextreme-vue/check-box';

export default {
    components: {
        DxCheckBox
    },
    data() {
        return {
            checkBox_value: undefined
        };
    },
    methods: {
        handleValueChange(e) {
            const previousValue = e.previousValue;
            const newValue = e.value;
            // Event handling commands go here
        }
    }
}
</script>
React
App.js
import React from 'react';
import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.css';

import CheckBox from 'devextreme-react/check-box';

class App extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            checkBox_value: undefined
        };

        this.handleValueChange = this.handleValueChange.bind(this);
    }

    handleValueChange(e) {
        const previousValue = e.previousValue;
        const newValue = e.value;
        // Event handling commands go here

        this.setState({
            checkBox_value: newValue
        });
    }

    render() {
        return (
            <CheckBox
                value={this.state.checkBox_value}
                onValueChanged={this.handleValueChange}
            />
        );
    }
}
export default App;

If you are going to change event handlers at runtime, or if you need to attach several handlers to the value change event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.

JavaScript
const valueChangedHandler1 = function (e) {
    const previousValue = e.previousValue;
    const newValue = e.value;
    // First handler of the "valueChanged" event
};

const valueChangedHandler2 = function (e) {
    const previousValue = e.previousValue;
    const newValue = e.value;
    // Second handler of the "valueChanged" event
};

$("#checkBoxContainer").dxCheckBox("instance")
    .on("valueChanged", valueChangedHandler1)
    .on("valueChanged", valueChangedHandler2);
See Also