lundi 3 avril 2017

Checkboxes that check another box

I am working with a webpage that is full of checkboxes, I want to check 1 (let's call that parent) checkbox that has a function to check multiple other checkboxes (let's call those child). This until now has succeeded with this piece of jquery code:

$(function(){
  $('#1').on('change',function(){
     $('#5,#456,#910,#1077,#982,#759,#1234,#392,#289,#956').prop('checked',$(this).prop('checked'));
  });
    $('.child').on('change',function(){
     $('#parent').prop('checked',$('.child:checked').length ? true: false);
  });

});

The only thing is; I want to give functions to the "child" checkboxes and to let them work when the "parent" checkbox is checked, but the functions don't seem to work when the child checkbox is checked by the parent checkbox. Only when you manually check the childbox with your cursor.

I hope my question was clear. I normally don't post on here

:)




Aucun commentaire:

Enregistrer un commentaire