0

I have the following code currently. What it does is initiate a checkbox when downloaded CSV file, but the data inside has all the fields. I only want to get those being checked in my checkboxes.

Is there a way in jQuery to do this as I haven't done it before.

<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>

  <!---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>
  </div>
// Downloading file into zip file.
$(document).ready(function() {
  $("#download").click(function() {
    var count = 0;

    if ($('#temperature').prop('checked'))
      count++;

    if ($('#illuminance').prop('checked'))
      count++;

    if ($('#button-state').prop('checked'))
      count++;

    if (count > 1) {
      window.location.href = 'https://api.thingspeak.com/channels/899906/feeds.csv?start=2019-11-12%2019:11:12&end=2019-11-13%2019:11:13';
    }
  });
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Gcobza
  • 432
  • 1
  • 5
  • 12
  • You are saying `but the data inside have all the fields.` what data do you refer to? – Carsten Løvbo Andersen Nov 15 '19 at 10:15
  • Yes the data inside CSV file only have all the fields, i want the fields being selected be on that CSV file. In another words it will confuse the user, that the data is not in the file. – Gcobza Nov 15 '19 at 10:22
  • If you're directly accessing the CSV file then there is no way to do this. You need some middle-ware to retrieve the data from the CSV file, filter it based on the checkboxes selected, then build a new CSV file with only the required columns. This is not a trivial task, and as such your question is far too broad. Also note that working with CSV files is not a scalable solution. You should look in to using a database as a datastore instead. – Rory McCrossan Nov 15 '19 at 10:24
  • At this point, we using thingspeak as cloud platform for micro-controller to send data to it. Or maybe i will ask thingspeak team about this, as i have never experience such trival task before – Gcobza Nov 15 '19 at 10:30
  • The [documentation](https://www.mathworks.com/help/thingspeak/rest-api.html) doesn't seem to mention the possibility of choosing what fields to get. You can only get them all or choose one field. – radulfr Nov 15 '19 at 10:32
  • Guys i think there is a restriction to this, what i meant by that i just ran a test on REST client using VS code, i can only access few fields due to REST api call. So i dont know how am i going to achieve such if i am using checkbox. Because REST APi client only access what is passed as parameters only on your URL. – Gcobza Nov 15 '19 at 10:41

0 Answers0