bootstrap switch getting value on change

7.2k views Asked by At

I am using bootstrap switch for setting value to NO when its OFF and Yes when its ON,

in HTML,

<input type="checkbox" id="limit" class="make-switch" data-on="success" data-on-color="success" data-off-color="danger" data-size="small">

in JS

    $("#limit").bootstrapSwitch();
    $('#limit').on( 'switchChange',function () {
    if ($("#limit").bootstrapSwitch('state') === true)
    {
        console.log('On');
    }
    else {
        console.log('Off');
    }
});

When i change switch i could not get any output on log,

What is wrong? and how can we get value of input field with bootstrap switch?

Thanks,

1

There are 1 answers

0
Rambler On BEST ANSWER

Instead of switchChange use the following event :

$('#limit').on('switchChange.bootstrapSwitch',function (e,data) {
    //.......
});