• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

jquery check-boxes

Hello Experts,

I got the solution below from sonawanekiran (an experts-exchange expert :-)).
i changed it a bit but it does not seem to work anymore. I was doing testings but nothing get it to work. can you please help?

* there are two check-boxes to check ... if both are checked then print the note.
$(document).ready(function() {
$(".checkboxes").click(function(){
  check_if_checkboxes_checked();
  });	
}); 

function check_if_checkboxes_checked(){
var flag = true;
$(".checkboxes").each(function(){
if (!$(this).is(':checked')) 
flag = false;
});
if (flag) {
$('#additionalNote').append('<span class="tbl_note">Please note: $10 will be added to the monthly payment.</span>');
}
else
$('#additionalNote span').remove();               
}

Open in new window

0
Refael
Asked:
Refael
  • 4
  • 3
2 Solutions
 
leakim971PluritechnicianCommented:
function check_if_checkboxes_checked(){
   if($(".checkboxes:checked").length < 2)
        $('#additionalNote').append('<span class="tbl_note">Please note: $10 will be added to the monthly payment.</span>');
        return true;
   }
   $('#additionalNote span').remove();              
}
0
 
RefaelAuthor Commented:

Hi leakim971,


no, it does not work.
i guess the above replace my script, right? and this code above should be in the "$(document).ready(function() {" and not after?
0
 
leakim971PluritechnicianCommented:
it only replace the second part, the check_if_checkboxes_checked function
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RefaelAuthor Commented:

leakim971,

first there is an error ( i have to remove the last '}' to get rid of the error.
second it does not work. here is the entire script.

$(document).ready(function() {
$(".checkboxes").click(function(){
    check_if_checkboxes_checked();
     });
 });

 function check_if_checkboxes_checked(){
   if($(".checkboxes:checked").length < 2)
        $('#additionalNote').append('<span class="tbl_note">Please note: $10 will be added to the monthly payment.</span>');
        return true;
	}
  $('#additionalNote span').remove()
}

Open in new window

0
 
saimazzCommented:
$(function() {
$(".checkboxes").click(function(){
    check_if_checkboxes_checked();
     });
 });

 function check_if_checkboxes_checked(){
   if($(".checkboxes:checked").size() == 2) {
        $('#additionalNote').append('<span class="tbl_note">Please note: $10 will be added to the monthly payment.</span>');
        return true;
	}
  $('#additionalNote span').remove()
}

Open in new window

checkbox-sample.html
0
 
leakim971PluritechnicianCommented:
Corrected (missing brace line 8):

$(document).ready(function() {
    $(".checkboxes").click(function(){
        check_if_checkboxes_checked();
    });
});

function check_if_checkboxes_checked() {
    if($(".checkboxes:checked").length < 2) {
        $('#additionalNote').append('<span class="tbl_note">Please note: $10 will be added to the monthly payment.</span>');
        return true;
    }
    $('#additionalNote span').remove()
}

Open in new window

0
 
RefaelAuthor Commented:

Guys. i am so so so sorry!
the problem was a misspelling of the class name 'checkboxs" instead of "checkboxes"... how duff  am i?
i am sorry i was bothering you..... thanks. both of the solution works just fine!!!
0
 
RefaelAuthor Commented:
read my comment. thank you so much guys!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now