title: Delete row from table and use bootstrap modal as confirmation
body: <p>I'm looking to delete a row from a table of users in my codeigniter framework project.</p>
  
  <p>I want to click the delete button, and have a modal window popup asking the user, if they are sure to delete the record, and upon clicking yes I would like to display another one confirming that it is complete.</p>
  
  <p>I'm just having a problem with passing the database dynamic ID to my ajax call without page refresh as I'm not sure how to go about it:-</p>
  
  <pre><code>&lt;div class = "wrapper"&gt;
  &lt;table class="table table-striped"&gt;
  
      &lt;thead class = "table_head"&gt;
      &lt;tr&gt;
          &lt;th&gt;ID&lt;/th&gt;
          &lt;th&gt;First Name&lt;/th&gt;
          &lt;th&gt;Last Name&lt;/th&gt;
          &lt;th&gt;Username&lt;/th&gt;
          &lt;th&gt;Class&lt;/th&gt;
          &lt;th&gt;Edit&lt;/th&gt;
          &lt;th&gt;Delete&lt;/th&gt;
      &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody class ="searchable"&gt;
  
      &lt;?php echo validation_errors(); ?&gt;
      &lt;?php if (is_array($users)) {?&gt;
  &lt;?php foreach($users as $user){?&gt;
      &lt;tr&gt;
  
          &lt;td&gt;&lt;?php echo $user-&gt;ID;?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $user-&gt;first_name;?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $user-&gt;last_name;?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $user-&gt;username;?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $user-&gt;class;?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;a href ="&lt;?php echo base_url().'index.php/User/edit_user/'. $user-&gt;ID ;?&gt;"&gt; Edit&lt;/a&gt;&lt;/td&gt;
          &lt;td&gt;&lt;a id = "mybutton" data-toggle="modal" data-target="#confirm_delete_modal" data-id="&lt;?php echo $user-&gt;ID;?&gt;"&gt; Delete&lt;/a&gt;&lt;/td&gt;
  
  
  
      &lt;/tr&gt;
  &lt;?php }}
      ?&gt;
      &lt;?php if(!$users){
          echo '&lt;div class="noresults"&gt;';
          echo 'No users available';
          echo '&lt;/div&gt;';
      }?&gt;
  &lt;/tbody&gt;
    &lt;/table&gt;
  </code></pre>
  
  <p>As can be seen above in the edit part, I need to pass the $user->ID to the modal window in order to delete the specified user.</p>
  
  <pre><code>  &lt;div id="confirm_delete_modal" class="modal fade" role="dialog"&gt;
    &lt;div class="modal-body"&gt;
        &lt;p id = "valcomplete"&gt; Are you sure you wish to delete this user?&lt;/p&gt;
    &lt;/div&gt;
    &lt;a id ="confirmbutton" style = "cursor:pointer;  color:black;"&gt;Yes&lt;/a&gt;
    &lt;a data-toggle="modal" data-target="#confirm_delete_modal" id ="exitbutton" style = " cursor:pointer; color:black;"&gt;No&lt;/a&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>  &lt;div id="deleted" class="modal fade" role="dialog"&gt;
        &lt;div class="modal-body"&gt;
            &lt;p id = "valcomplete"&gt; User deleted&lt;/p&gt;
        &lt;/div&gt;
        &lt;a data-toggle="modal" data-target="#deleted" id ="exitbutton" style = "color:black;"&gt;Exit&lt;/a&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>What I have now:</p>
  
  <pre><code>   $('#mybutton').click(function(){
      var ID = $(this).data('id');
      $('#confirm-button').data('id', ID); //set the data attribute on the modal button
  });
  
  $('#confirm-button').click(function(){
      var ID = $(this).data('id');
      $.ajax({
          url: "&lt;?php echo base_url(); ?&gt;index.php/Admin/delete_user/"+ID,
          type: "post",
          data:ID,
          success: function (data) {
            $("#confirm_delete_modal").modal('hide');
            $("#deleted").modal('show');
  
          }
        });
  });
  </code></pre>
  
  <p>Can anyone help me ?? Thanks</p>