I am developing CMS and on Add Form I'm using Bootstrap-switch in my form. But It always return checked
or on
value.
JSFiddle
CODE
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://www.bootstrap-switch.org/docs/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http://www.bootstrap-switch.org/dist/css/bootstrap3/bootstrap-switch.css">
<script type='text/javascript' src="http://www.bootstrap-switch.org/docs/js/bootstrap.min.js"></script>
<script type='text/javascript' src="http://www.bootstrap-switch.org/dist/js/bootstrap-switch.js"></script>
<script type='text/javascript'>
$(window).load(function(){
var s = $('#status').val();
$("#status").change(function(){
alert(s);
});
});
</script>
</head>
<body>
<input type="checkbox" id="status" name="status" checked>
</body>
</html>
Change from
var s = $('#status').val();
$("#status").change(function(){
alert(s);
});
Into
$("#status").change(function(){
if(this.checked == true)
{
s = 'on';
}
else
{
s = 'off';
}
alert(s);
});
Just read the checked status in this way:
$("#status").change(function(){
alert(this.checked);
});
Fiddle Example
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