我在名为people_amount的控制器中调用此函数时遇到问题
//function inside people_amount controller
function ajax_amount($cName)
{
$this->db->select('Amount');
$this->db->where('Country_Name', $cName);
$result = $this->db->get('tb_country');
$amount = $result->row('Amount');
echo json_encode($amount) ;
}
这是我的js
<script type="text/javascript">
jQuery( document ).ready(function() {
function changeTest(obj){
//get name from dropdown
$cName = (obj.options[obj.selectedIndex].value);
//call function to get amount
$amount = $this->ajax_amount($cName);
}
});
</script>
这是我的观点
<div class="col-md-6">
<?php
$atribut_blangko = 'class="form-control" onChange="changeTest(this)"';
$selectedBlangko = $values->ID_Blangko;
echo form_dropdown('ID_Blangko', $dropdown_Blangko, $selectedBlangko, $atribut_blangko);
?>
</div>
<div class="col-md-6">
//show the amount in the form input
<?php echo form_input('Amount', $getAmountfromJS, 'id="amount" class="form-control" readonly="true"') ?>
</div>
我在这里尝试的是当我从下拉列表中选择一个名称时,输入表单将显示所选名称的金额。我该怎么做呢?任何帮助将非常感谢。感谢