mercredi 30 novembre 2016

How to clear all checkboxes and reset the value of the checkbox in javascript

I am trying to clear all checkboxes in a map I've built. The checkboxes turn on some features of the map. Also, I can check a few and only see a few of the items and not all. For example, I have a button to show all wells and then a sub menu to allow for users to select individual owners of the wells. Once the user has checked the individual owners within the sub menu they can filter to see only those. When the user clicks the 'clear all' button it clears all the checkboxes as it should, but within the wells sub menu it acts like those individual boxes that were checked stay checked and keep that state. When I click the show all wells button again it then only shows me the sub menu wells that were checked.

// here give the sub menu checkboxes a state when clicked.

    $(".wellProducer").on("click",function(){
      $(this).val(this.checked ? 1 : 0);
    });

// once checked make only that owner visible

    $(".wellProducer").click(function(){
       if(this.checked == true){
          map.filters.selectedProducers.push(this.value);
       }
       if(this.checked == false){
           var index = map.filters.selectedProducers.indexOf(this.value);
           if (index > -1){
               map.filters.selectedProducers.splice(index, 1);
           }
        }
   });

// here is the clear all button click

    $("#resetBtn").click(function(){
       $(clearFunction).click();
    });

// here is the clear function

   function clearFunction(index){

      if(map.filters.showWells == 1){
          map.filters.showWells = 0;
      }
      $("input:checkbox").prop("checked", false);

     ReDraw();

     }




Aucun commentaire:

Enregistrer un commentaire