Monday, May 20, 2024
183
rated 0 times [  185] [ 2]  / answers: 1 / hits: 18028  / 11 Years ago, wed, july 17, 2013, 12:00:00

Why is that checkbox inside the bootstrap modal not working?



I use this code to make it working but still have a problem



documentBody.on('click','.checkInp',null,function(e) { 
var checkbox = $(this).find(:checkbox),
checked = checkbox.is(:checked);
checkbox.prop(checked, !checked);

});

documentBody.on('click','.checkInp :checkbox',null,function(e) {
$(this).parent('span').trigger('click');

});


when i click it there is no check appears when its unchecked or it is not uncheck when its check? but if i click the span area the checkbox is marked as check or uncheck



here is my fiddle


More From » twitter-bootstrap

 Answers
29

Guess you try to overcome bootstrap modals e.preventDefault() in click events - this is why it never works. Also the two events seems to obsulete each other?



Try this instead :



$('.checkInp input:checkbox').on('click', function(e) {

// prevents the event from bubbling up the DOM tree
// eg the modal from cancelling the event
e.stopImmediatePropagation();

var checked = (e.currentTarget.checked) ? false : true;
e.currentTarget.checked=(checked) ? false : checked.toString();
});


forked fiddle : http://jsfiddle.net/AurPX/


[#76942] Tuesday, July 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
calicinthias

Total Points: 447
Total Questions: 101
Total Answers: 118

Location: Botswana
Member since Sat, Dec 31, 2022
1 Year ago
;