mercredi 15 août 2018

Jquery if/else statements using 2 checkboxes

I am building a chart that needs to change values depending on two checkboxes. I have 2 datasets, so I created 4 values for each. This is what I got so far:

HMTL / Checkboxes:

<input id="toggle-1" type="checkbox"/>

<input id="toggle-2" type="checkbox"/>

Jquery condition:

$("input#toggle-1[type='checkbox']").click(function (event) {
 var data = chart2.config.data;
 if ($(this).is(':checked')) {
  data.datasets[0].data = x;
  data.datasets[1].data = x;
 } else {
  data.datasets[0].data = x;
  data.datasets[1].data = x; 
}
chart2.update();
});

This would be the set up for only one checkbox (toggle-1) assuming I would replace the "x"s with each variable accordantly.

So how do I implement the condition for second checkbox?

Any help would be very appreciated. Thank you!




Aucun commentaire:

Enregistrer un commentaire