Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
146
rated 0 times [  150] [ 4]  / answers: 1 / hits: 37675  / 10 Years ago, wed, june 18, 2014, 12:00:00

I use Bootstrap switch plugin to make my checkboxes looks like switch buttons. I need to check if the checkbox is checked in jQuery. I Googled a lot and I tried some advice and code snippets but without success.



I think the cleanest code I found is



$('#checkbox').attr('checked');


but it still wont work on my website. I have declared jQuery in head. I try to use this snippets on non-bootstrap-switch-checkboxes but still no success.



JS:



 <script>
$(function(){
$(.odeslat).click(function(){
$('#pozadavky').slideUp(100);
$('#datumpick').slideDown(300);

var typpaliva = 'nic';
var malpg = 'nic';¨

/***Important condition***/

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/>

More From » jquery

 Answers
7

Use :



if ($('#uho').is(':checked')) {


instead of



if ($('#uho').attr('checked')) {

[#70531] Monday, June 16, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josefn

Total Points: 251
Total Questions: 93
Total Answers: 84

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;