title: how to insert values from toggle button to database without submit button
body: <p>I am trying to update values in the database using toggle button 
  Here is my script</p>
  
  <pre><code>$(document).ready(function () {
     $('input.status').on('change', function () {
         var decision = $(this).val();
         var id = $('td.myvalue').html();     
          alert(decision);
          alert(id);
          $.ajax({
          type: "POST",
          url: "/CodeIgniter/users/Users/update",
          data: {decision: decision, id: id},
          success: function (msg) {
  
          $('#autosavenotify').text(msg);
         }
      })
    });
  });
  </code></pre>
  
  <p>DataTable</p>
  
  <pre><code>&lt;table class="table table-striped table-hover DataTables "id="DataTables" cellspacing="0" width="100%"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Icon&lt;/th&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Group Users&lt;/th&gt;
              &lt;th&gt;Status&lt;/th&gt;
               &lt;th&gt;Action&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;?php $i = 0;
              foreach ($getTableGroup as $value) { ?&gt;
          &lt;tr&gt;
              &lt;td class="myvalue"&gt;
                  &lt;?= $value-&gt;id ?&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;?= $value-&gt;group_name ?&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;input class="tagsinput form-control" type="text" value="sam"/&gt;
              &lt;/td&gt;
              &lt;input class="myid" type="hidden" value="&lt;?= $value-&gt;id ?&gt;"/&gt; 
              &lt;td &gt;
                  &lt;?php if ($value-&gt;group_status == 'on'): ?&gt;
                  &lt;div class="switch"&gt;
                      &lt;div class="onoffswitch"&gt;
                          &lt;input type="checkbox" checked class="onoffswitch-checkbox status" id="example&lt;?= $i ?&gt;" name="group-status" &gt;
                          &lt;label class="onoffswitch-label" for="example&lt;?= $i ?&gt;"&gt;
                              &lt;span class="onoffswitch-inner"&gt;&lt;/span&gt;
                              &lt;span class="onoffswitch-switch"&gt;&lt;/span&gt;
                          &lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;?php elseif ($value-&gt;group_status == 'off'): ?&gt;
                  &lt;div class="switch"&gt;
                      &lt;div class="onoffswitch"&gt;
                          &lt;input type="checkbox" checked class="onoffswitch-checkbox status" id="example&lt;?= $i ?&gt;" name="group-status"&gt;
                          &lt;label class="onoffswitch-label" for="example&lt;?= $i ?&gt;"&gt;
                              &lt;span class="onoffswitch-inner"&gt;&lt;/span&gt;
                              &lt;span class="onoffswitch-switch"&gt;&lt;/span&gt;
                          &lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;?php endif; ?&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;?php
              $i++;
              }
          ?&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>My code is working fine but the issue is in scripting section where when I click on toggle button the id does not increase every time id came in the alert box is 1 but in datatable it show the Id number from database</p>