Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 469.3k

How to get two fields on your thingspeak using Jquery?

Nov 22 2019 3:25 AM
I am struggling to get two fields on one URL parameter using thingspeak REST API. I have the following that attempts to do such, but im bit stuck in the middle. The idea is i have 3 checkboxs, each of them so far is doing is allowing and downloading that specific field. I want a way where if i do the checking on my if statement from those checkboxs, it should allow me to download those fields as being 2 only on my CSV file. Here is my code for the checkbox in both HTML and Jquery.
 
<div class = "custom-control custom-checkbox">
<input type = "checkbox" class="custom-control-input" id="illuminance">
<label class = "custom-control-label" for = "illuminance">Illuminance</label>
</div>
<div class ="custom-control custom-checkbox">
<input type ="checkbox" class="custom-control-input" id="button-state">
<label class ="custom-control-label" for = "button-state">Button-State</label>
</div>
<!---Downloading File using
Jquery with Buttons---->
<div class="form-group"><br>
<div class="col-md-1.9 text-center">
<button id="download" name="download" class="btn btn-warning">Download</button><br>
</div><br>
// checking for per number of entries to read.
$(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');
}
});
});
// checking for either of fields.
$(function() {
$("#download").click(function(e){
e.preventDefault();
});
});
 

Answers (1)