Click here to Skip to main content
15,888,321 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I cant seem to do checks correctly in order in my Jquery, my function loads dont fire in order as per user to select in sequence. Please help me to improve the logic, thanks.

What I have tried:

JavaScript

div class="custom-control custom-checkbox">
      <input type="checkbox" class ="custom-control-input" id="temperature">
    <label class = "custom-control-label" for="temperature">Temperature</label>
  </div>

  <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 class="form-group"><br>

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

    <div class="col-md-1.9 text-center">
      <button id="download" name="download" class="btn btn-warning" >Download</button><br>

   $(function() {
        $("#download").click(function(e) {
            e.preventDefault();
            if($('#temperature,#illuminance').is(':checked')){
                window.open("https://api.thingspeak.com/channels/899906/feeds/last.csv?api_key=F35GLOFJ8L99D0OM", "_blank");
            }

        });
    });

   // 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?results=10');
      }
  if($('#illuminance').is(':checked')){
    window.open('https://api.thingspeak.com/channels/899906/fields/2.csv?results=10');
      }
  if($('#button-state').is(':checked')){
    window.open('https://api.thingspeak.com/channels/899906/fields/8.csv?results=10');
      }

    });

});
Posted
Updated 29-Nov-19 19:10pm
Comments
Mehul M Thakkar 28-Nov-19 6:18am    
jQuery can not persist order on selection, that you have to do from your side.

1 solution

if i am not wrong using jquery of
HTML
$('#temperature')
return results as List
for reading single element you should use
HTML
document.getElementById("temperature").checked
or you can still use jquery like
HTML
$('#temperature')[0].checked
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900