[Fixed]-Django: How do I get multiple values from checkboxes in dataTable

1👍

You can use a hidden input field(type hidden) containing the string (comma separated value), which can later be received on server side as string and further it’s splited using split method which will result in desired list

   <form> 
      <input id="result" type="hidden" name="result"> 
      <!--your data table goes here--> 
   </form> 

  <script> 
  $(document).ready(function(){ 
     var resultarray=[]; 
     $('form input:checkbox').on('change', function(){ 

      var orderValue=$(this).val();

     // if string already available then remove(uncheck operation) 
     if(resultarray.indexOf(orderValue)!=-1) 
     { 
        resultarray.splice(resultarray.indexOf(orderValue), 1);
      } 
     else 
     { 
      //if sting is not available then add(check operation) 
      resultarray.push(orderValue);
     } 

   var text=""; 
   for(x in resultarray) 
   { 
     text+=x+",";
     //you may add an extra condition for not adding comma at last element
   }
   $("#result").val(text);
  }); 
}); 

Leave a comment