I am using codinator select id show value other input box but not show any values.please help...
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
alert('ajax completed. Response: '+data) fine but after vh_stock getting value not show
<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
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);
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
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 error
<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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.