I use the Switch Bootstrap plugin to make my checkboxes look like toggle buttons. I need to check if the checkbox is checked in jQuery. I searched a lot and I tried some tips and code snippets, but to no avail.
I think the cleanest code I found is
$('#checkbox').attr('checked');
but it still does not work on my site. I declared jQuery in the head. I am trying to use these snippets on checkboxes other than bootstrap-switch-checkbox, but still to no avail.
JS:
<script>
$(function(){
$(".odeslat").click(function(){
$('#pozadavky').slideUp(100);
$('#datumpick').slideDown(300);
var typpaliva = 'nic';
var malpg = 'nic';ยจ
if ($('#uho').attr('checked')) {
$.cookie("typpaliva", "Diesel");
}
else {
$.cookie("typpaliva", "Benzin");
}
$.ajax({
url: 'http://podivej.se/script_cas.php',
data: {druh: '30'},
type: "POST",
success: function(data){
alert($.cookie('typpaliva'));
alert($.cookie('malpg'));
}
});
});
});
</script>
HTML
<input type="checkbox" name="testcheckbox" id="uho"/>
source
share