merch89 merch89 - 1 month ago 16
jQuery Question

Popups for checking/unchecking a checkbox

I have prompts that produce a popup when a box is ticked and unticked. There looks to be a line of redundant code, but when removed the functions no longer work. So maybe not so redundant:-) But the #id doesn't match to anything (currently set as CAPS to not match)

Any ideas why this is interfering?

$('#checkbox').click(function() {
if ($("#checkbox").is(':checked')) {
if (confirm('Are you sure you want to CONFIRM the order?')) {
$('#CHECKBOX').click();
}
}
});

$("#checkbox").on('change', function() {
this.checked = !this.checked ? !confirm('Do you really want to change this to NOT RECEIVED?') : true;
});




http://jsfiddle.net/5nd1wj54/1/

Answer

Here is what I think you mean

$('#checkbox').click(function() {
  if (this.checked) {
    this.checked = confirm('Are you sure you want to CONFIRM the order?')); 
  }    
  else {
    this.checked = !confirm('Do you really want to change this to NOT RECEIVED?'); 
  }  
});