Reputation: 45737
Hello I have the following function that is NOT working at the moment..
What I need is to show some DIVs if at least 1 checkbox is checked in my form, if no checkboxes are checked those Divs stay hidden. Also this should be fired Everytime based on what the user does, and not only the first time...How can I do it?
Thanks
function Checkbox() {
if($("#tuitting_form input:checkbox:checked").length > 0){
$("#send_message").show();
$("#remove_accounts").show();
}else{
$("#send_message").fadeOut();
$("#remove_accounts").fadeOut();
}
}
Upvotes: 0
Views: 57
Reputation: 69905
Try this
$(function(){
$("#tuitting_form input:checkbox").change(function(){
if($("#tuitting_form input:checkbox:checked").length > 0){
$("#send_message").show();
$("#remove_accounts").show();
}else{
$("#send_message").fadeOut();
$("#remove_accounts").fadeOut();
}
}
});
Upvotes: 0
Reputation: 78520
seems to work for me. Just add it to the changed event listener for checkboxes. See my example.
$("input:checkbox").change(function(){
if($("input:checkbox:checked").length > 0){
$("#send_message").show();
$("#remove_accounts").show();
}else{
$("#send_message").fadeOut();
$("#remove_accounts").fadeOut();
}
})
Upvotes: 1