选择选项值ID,然后使用javascript和codinator在值中显示其他输入框,但不显示值

时间:2019-12-12 07:20:37

标签: javascript php

我正在使用codinator select id显示值其他输入框,但未显示任何值。请帮助...

在此处选择“选项”查看页面代码

工作正常

<select  id="tanktype" name="tankno" class="form-control tankno" required >
    <option>Select</option>
     <?php
       $queryw = $this->db->where('vh_rdi',$_SESSION['rdi']);
       $queryw = $this->db->get('vh_stock');
       if ($queryw->num_rows() > 0)  
         {
         foreach ($queryw->result() as $roww)
           {
     ?>                             
    <option value="<?php echo $roww->vh_id; ?>"><?php echo $roww->vh_id; ?></option>
   <?php } } ?>
</select>

结果显示视图字段位于同一页面,但未显示任何值

<input   name="vh_stock"  type="text" class="vh_stock" value="">

此处的JavaScript代码

警告('ajax已完成。响应:'+数据)很好,但是在vh_stock获得价值后未显示

<script>
        $(document).ready(function(){
        $('#tanktype').change(function(){
            //Selected value
            var id = $(this).val();
            alert("value in js "+id);

            //Ajax for calling php function
            $.post('<?php echo base_url()."index.php/Mechanical_rdirecived/viewtankstock"; ?>', { dropdownValue: id }, function(data){
                alert('ajax completed. Response:  '+data);//working fine result

                //do after submission operation in DOM
                 $(".vh_stock").val(data.vh_stock); //value is not getting 
                 //$(".id1").val(data.id1);                      
              //}, 'json')
            });
        });
});
    </script>  

enter image description here

控制器=> Mechanical_rdirecived / viewtankstock

工作正常

public function viewtankstock()  
{ 

$id = $this->input->post('dropdownValue');
$this->load->model('Model_fuel_rdirecived');
$this->Model_fuel_rdirecived->viewtankstock($id);

}

Model => Model_fuel_rdirecived-> viewtankstock($ id);

工作正常

public function viewtankstock($id) {

$this->db->where('vh_id', $id);  
$query = $this->db->get('vh_stock');
  if ($query->num_rows() > 0)  
    {
   $data['foreach'] = $query->result();
   $id1 = $data['foreach'][0]->vh_id; 
   $vh_stock = $data['foreach'][0]->vh_stock;
   $arr =array("vh_stock"=>"$vh_stock","id1"=>"$id1");
   print_r($arr);
 echo json_encode($arr);
    }

}

1 个答案:

答案 0 :(得分:0)

尝试一下:

<input   name="vh_stock"  type="text" class="vh_stock">

收件人:

<input   name="vh_stock"  type="text" class="vh_stock" value="">

尝试:

控制器=> Mechanical_rdirecived / viewtankstock

public function viewtankstock()  
    { 
     $id = $this->input->post('reg_no');
     $this->load->model('Model_fuel_rdirecived');
     $arr = $this->Model_fuel_rdirecived->viewtankstock($id);
     echo json_encode($arr);
   } 

Model => Model_fuel_rdirecived-> viewtankstock($ id);

public function viewtankstock($id) {
    $this->db->where('vh_id', $id);  
    $query = $this->db->get('vh_stock');

      if ($query->num_rows() > 0)  
        {
       $data['foreach'] = $query->result();

       $id1 = $data['foreach'][0]->vh_id; 

       $vh_stock = $data['foreach'][0]->vh_stock;

       $arr =array("vh_stock"=>"$vh_stock","id1"=>"$id1");
       return $arr;
        }

}

JavaScript错误

 <script>
        $(document).ready(function(){
        $('#tanktype').change(function(){
            var id = $(this).val();
            $.post('<?php echo base_url()."index.php/Mechanical_rdirecived/viewtankstock"; ?>', { dropdownValue: id }, 
            function(data){

                alert('ajax completed. Response:  '+data);//msg=ajax completed. Response:    {"vh_stock":"600","id1":"4"}

                 $(".vh_stock").val(data.vh_stock);//no recived how can no recived  data
                 $(".id1").val(data.id1); //no recived how can no recived  data
              },)
            });
        });

    </script>

结果

ajax completed. Response:  undefined