Dark
Dark

Reputation: 124

Getting the value of my amount column and pass it to my textbox. (Codeigniter)

Newbie here, My target is, how can I pass the value of my amount column to my textbox? I did the same logic as i pass the ID using script (below), but it's not working. I'm trying different approach but none of them is working. Hoping someone can help. Thank you in advance.

enter image description here

Views:

<?php 
              
                    foreach($result as $rows) {     ?>
                   <?php if($rows->status==='pending'){ ?>
                <tr>
                
                <td><?php echo $rows->userID; ?></td>
                <td><?php echo $rows->transID; ?></td>              
                <td><?php echo $rows->amount; ?></td>
                <td><?php echo $rows->currentBalance; ?></td>
                <td><?php echo $rows->status; ?></td>
                <td>
                
 <button data-id="<?php echo $rows->transID?>"  ustatus="approved" class="showmodal fundTable btn btn-success btn-sm text-bold user_status">
   <?php echo $rows->transID?> accept
</button>


<div id="fundModal" class="modal" tabindex="-1" role="dialog">
<form method="post" action="<?php echo site_url('ewallet/statuschanged')?>">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
      
          <div class="form-group">
                            <label for="">transID</label>
                            <input type="text" id="transID" name="transID" value="">
                          </div>
                          <div class="form-group">
                            <label for="">Amount</label>
                            <input type="text" id="amount" name="amount" value="<?php echo $rows->amount; ?>">
                          </div>
                          <div class="form-group">
                            <label for="">Status</label>
                            <input type="text" name="status" id="user_status" value="">
                          </div>
   
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Save changes</button>
        </form>
      </div>
    </div>
  </div>
</div>

Controllers:

public function statuschanged($transID = 0)
    {
        
        
        $this->ewallets->statuss($transID);
    
    }

Model:

function statuss($transID) {
            
            $transID = $this->input->post('transID');
            $status = $this->input->post('status');
           
            
            $data = array('status' => $status );
            $this->db->where('transID',$transID);
            $this->db->update('cash_out', $data); //Update status here
            
            return redirect('ewallet/cashout');
        }

Script:

<script>

$('.showmodal').on('click', function(e){
    e.preventDefault();
  
  $('#transID').val(this.dataset.id); // passing of ID to my textbox
  $('#fundModal').modal('show')
})


$('#fundModal').on('hidden.bs.modal', function () {
  $('#transID').val('')
  $('#ustatus').val('')
})
    </script>

Upvotes: 1

Views: 65

Answers (1)

Kanji Taviya
Kanji Taviya

Reputation: 119

Step 1 -

<button data-amount="<?php echo $rows->amount?>" data-id="<?php echo $rows->transID?>" ustatus="approved" class="showmodal fundTable btn btn-success btn-sm text-bold user_status">
   <?php echo $rows->transID?> accept
</button>

Step 2 -

$('.showmodal').on('click', function(e){
    e.preventDefault();
  
  $('#amount').val($(this).data("amount")); // passing amount to textbox
  $('#transID').val(this.dataset.id); // passing of ID to my textbox
  $('#fundModal').modal('show')
});

Step 3 -

When model close - $('#amount').val('');

Upvotes: 2

Related Questions