简体   繁体   English

选择 Option value id 并使用 javascript & codinator 在 value 中显示其他输入框,但 value 未显示

[英]Select Option value id and show other input box in value using javascript & codinator but value is not show

I am using codinator select id show value other input box but not show any values.please help...我正在使用 codinator select id 显示值其他输入框但不显示任何值。请帮助...

select Option view page code here在此处选择选项查看页面代码

working fine工作正常

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

Result show view field same page but not show any value结果显示视图字段相同页面但不显示任何值

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

javaScript code here这里的 JavaScript 代码

alert('ajax completed. Response: '+data) fine but after vh_stock getting value not show警报('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>  

在此处输入图片说明

controller => Mechanical_rdirecived/viewtankstock控制器 => Mechanical_rdirecived/viewtankstock

working fine工作正常

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);模型=>Model_fuel_rdirecived->viewtankstock($id);

working fine工作正常

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);
    }

} }

Try this :尝试这个 :

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

TO :到 :

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

Try:尝试:

controller => Mechanical_rdirecived/viewtankstock控制器 => 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);模型=>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 error 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>

result结果

ajax completed. Response:  undefined

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM