猿问

选择选项值 id 并使用 javascript & codinator 在值中显示其他输入框

我正在使用 codinator 选择 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 代码在这里


alert('ajax completed. Response: '+data) 很好,但在 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>  

控制器 => Mechanical_rdirecived/viewtankstock


工作正常


public function viewtankstock()  


$id = $this->input->post('dropdownValue');

$this->load->model('Model_fuel_rdirecived');

$this->Model_fuel_rdirecived->viewtankstock($id);

}


模型=>Model_fuel_rdirecived->viewtankstock($id);


慕田峪7331174
浏览 125回答 1
1回答

哆啦的时光机

尝试这个 :<input&nbsp; &nbsp;name="vh_stock"&nbsp; type="text" class="vh_stock">至 :<input&nbsp; &nbsp;name="vh_stock"&nbsp; type="text" class="vh_stock" value="">尝试:控制器 => Mechanical_rdirecived/viewtankstockpublic function viewtankstock()&nbsp;&nbsp;&nbsp; &nbsp; {&nbsp;&nbsp; &nbsp; &nbsp;$id = $this->input->post('reg_no');&nbsp; &nbsp; &nbsp;$this->load->model('Model_fuel_rdirecived');&nbsp; &nbsp; &nbsp;$arr = $this->Model_fuel_rdirecived->viewtankstock($id);&nbsp; &nbsp; &nbsp;echo json_encode($arr);&nbsp; &nbsp;}&nbsp;模型=>Model_fuel_rdirecived->viewtankstock($id);public function viewtankstock($id) {&nbsp; &nbsp; $this->db->where('vh_id', $id);&nbsp;&nbsp;&nbsp; &nbsp; $query = $this->db->get('vh_stock');&nbsp; &nbsp; &nbsp; if ($query->num_rows() > 0)&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp;$data['foreach'] = $query->result();&nbsp; &nbsp; &nbsp; &nbsp;$id1 = $data['foreach'][0]->vh_id;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;$vh_stock = $data['foreach'][0]->vh_stock;&nbsp; &nbsp; &nbsp; &nbsp;$arr =array("vh_stock"=>"$vh_stock","id1"=>"$id1");&nbsp; &nbsp; &nbsp; &nbsp;return $arr;&nbsp; &nbsp; &nbsp; &nbsp; }}JavaScript 错误&nbsp;<script>&nbsp; &nbsp; &nbsp; &nbsp; $(document).ready(function(){&nbsp; &nbsp; &nbsp; &nbsp; $('#tanktype').change(function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var id = $(this).val();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.post('<?php echo base_url()."index.php/Mechanical_rdirecived/viewtankstock"; ?>', { dropdownValue: id },&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function(data){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('ajax completed. Response:&nbsp; '+data);//msg=ajax completed. Response:&nbsp; &nbsp; {"vh_stock":"600","id1":"4"}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(".vh_stock").val(data.vh_stock);//no recived how can no recived&nbsp; data&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(".id1").val(data.id1); //no recived how can no recived&nbsp; data&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; </script>结果ajax completed. Response:&nbsp; undefined
随时随地看视频慕课网APP
我要回答