Search code examples
twitter-bootstrapbootstrap-switch

bootstrap switch getting value on change


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,


Solution

  • Instead of switchChange use the following event :

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