I'm using bootstrap switch & i want to get checkbox value on click on switch. I've tried this but i din't get the value. Could you check my code bellow & let me know where i did wrong
$('.make-switch').bootstrapSwitch('state');
$('#price_check').click(function () {
//alert('Test');
var check = $(this).val();
console.log(check)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.4/css/bootstrap2/bootstrap-switch.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.4/js/bootstrap-switch.min.js"></script>
<div class="margin-bottom-10">
<input type="checkbox" class="make-switch" id="price_check" name="pricing" data-on-color="primary" data-off-color="info" value="true">
</div>
I guess all these solutions are old news as of v5?
in any case none of these work for me. So I used this solution
$('#orderSwitch').on('change', function() {
console.log($(this).is(':checked'));
});
Tamara,
Bootstrap Switch has an onSwitchChange
property that will be able to give you the state of the toggle. Please see this fiddle: https://jsfiddle.net/learnwithclyde/to2hng3f/
$("#price_check").bootstrapSwitch({
onSwitchChange: function(e, state) {
alert(state);
}
});
The above code snippet is how you would implement onSwitchChange
property and get the state
of the toggle control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With