Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

javascript - 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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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('');


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...