You're getting confused between IDs and classes.
$("#foo")
selects an element with id="foo"
;$(".foo")
selects an element with class="foo"
;
So your selector
$('.temperature')
will not match any elements, because there are no elements with that CSS class. You should be using
$('#temperature')
instead, as you have on the previous line.
But even then, it's not clear what you're trying to achieve. You start with a variable set to
0
; if the checkbox is checked, you decrement that variable, making it
-1
; then, if the variable is less than
1
, you perform some action. But the variable will
always be less than
1
!
And setting
window.location.href
will almost certainly stop any other scripts on the current page from running, so only one file will ever be downloaded.
Perhaps you want something like this?
$(function(){
$("#download").click(function(e){
e.preventDefault();
if ($('#temperature').is(':checked')){
window.open('https://api.thingspeak.com/channels/899906/fields/1.csv');
}
if ($('#illuminance').is(':checked')){
window.open('https://api.thingspeak.com/channels/899906/fields/2.csv');
}
if ($('#button-state').is(':checked')){
window.open('https://api.thingspeak.com/channels/899906/fields/8.csv');
}
});
});