Click here to Skip to main content
15,936,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am struggling to find a way to make my checkbox to either choose either one or two nor combination. What the code does currently allows one to select checkbox at a time and you can download the file format. I want to find a way that is possible if a user select neither one, two or combination of the checkbox be able to download the file format based on my given code below that have attempted to write.

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

 $(function() {
    $("#download").click(function(e){
    e.preventDefault();
      if($('temperature').is(':checked')){}
      if($('illuminance').is(':checked')){}
      if($('button-state').is(':unchecked')){}
      window.open('https://api.thingspeak.com/channels/899906/feeds.csv?start=2019-11-19%2019:11:19&end=2019-11-20%2019:11:20');
    });
  
  });
Posted
Updated 20-Nov-19 1:14am
Comments
Kornfeld Eliyahu Peter 20-Nov-19 5:46am    
It is unclear...
Are you looking for force valid combination of the 3 checkboxes you have?
gcogco10 20-Nov-19 5:47am    
Yes something like that
Kornfeld Eliyahu Peter 20-Nov-19 6:01am    
You probably better off using radio buttons... The UI will be clear to the end user... In you case you should explain (via some message) why you block certain clicks...

1 solution

This will run your window.open if any of the checkboxes are checked

JavaScript
if($('temperature').is(':checked') || $('illuminance').is(':checked') || $('button-state').is(':checked')){
      window.open('https://api.thingspeak.com/channels/899906/feeds.csv?start=2019-11-19%2019:11:19&end=2019-11-20%2019:11:20');
}
 
Share this answer
 

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