【问题标题】:Passing the value of button to textbox and update the status. (Codeigniter)将按钮的值传递给文本框并更新状态。 (代码点火器)
【发布时间】:2020-12-30 09:43:49
【问题描述】:

如何将 "ACTIVE" 状态属性的值传递给我的文本框?我的目标是通过按 ACTIVE 按钮来更新我的用户的状态。知道用户状态为待处理。我可以轻松传递用户 ID,但在传递状态方面遇到问题。

我在下面提供了屏幕截图。

观看次数:

<button data-id="<?php echo $rows->transID?>"  ustatus="Active" class="showmodal" class="fundTable btn btn-success btn-sm text-bold user_status">
   <?php echo $rows->transID?> active
</button>  // I can pass the ID to my textbox easily, but the status is not working.

<div id="fundModal" class="modal" tabindex="-1" role="dialog">
  <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">
        <form action="#">
          <div class="form-group">
            <label for="">UserID</label>
            <input type="text" id="usertransferid">
          </div>
          <div class="form-group">
            <label for="">status</label>
            <input type="text" name="status" id="user_status" value="">
          </div>
        </form>
      </div>
   
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

脚本:

<script>

$('.showmodal').on('click', function(e){
    e.preventDefault();
  
  $('#usertransferid').val(this.dataset.id);
  $('#fundModal').modal('show')
})


$('#fundModal').on('hidden.bs.modal', function () {
  $('#usertransferid').val('')
  $('#ustatus').val('')
})
    </script>
    
<script type="text/javascript">
    $(document).on('click','.user_status',function(){

     
        var status = $(this).attr('ustatus');
        //get attribute value in variable

    
        $('#user_status').val(status);  //I tried passing the user status but it's not working

    

    }); 
</script>

控制器:

public function user_status_changed()
{
    //get hidden values in variables
    $id = $this->input->post('id');
    $status = $this->input->post('status');

        


    $data = array('status' => $status );

    
    $this->db->update('users', $data); //Update status here

    //Create success message
    $this->session->set_flashdata('msg',"User status has been changed successfully.");
    $this->session->set_flashdata('msg_class','alert-success');

    return redirect('welcome/users');
}

【问题讨论】:

    标签: javascript html codeigniter


    【解决方案1】:

    您没有更新状态,因为您使用 $(this).attr('ustatus'); 未定义

    这是因为$(this) 指向类user_status,它没有属性ustatus

    你想要的是你的按钮的attribute usstatus的值,它有一个class showmodal,所以你需要把你的代码改成:

    $(document).on('click','.user_status',function(){
        var status = $('.showmodal').attr('ustatus');   // check the change here
        $('#user_status').val(status); 
    });
    

    P.S:在您的按钮定义中,您使用了两次class="...",这是错误的。做吧:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-02
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多