Retrieve variable from javascript into controller's function
<p>I have problem with calling this function in my controller named people_amount</p>

<pre><code>//function inside people_amount controller
function ajax_amount($cName)
{
    $this-&gt;db-&gt;select('Amount');
    $this-&gt;db-&gt;where('Country_Name', $cName);
    $result = $this-&gt;db-&gt;get('tb_country');
    $amount = $result-&gt;row('Amount');
    echo json_encode($amount) ;
}
</code></pre>

<p>Here's my js</p>

<pre><code>&lt;script type="text/javascript"&gt;
jQuery( document ).ready(function() {
    function changeTest(obj){
         //get name from dropdown
         $cName = (obj.options[obj.selectedIndex].value);

         //call function to get amount
         $amount = $this-&gt;ajax_amount($cName);
    }
});
&lt;/script&gt;
</code></pre>

<p>Here's my view</p>

<pre><code>&lt;div class="col-md-6"&gt;
    &lt;?php
         $atribut_blangko = 'class="form-control" onChange="changeTest(this)"';
         $selectedBlangko = $values-&gt;ID_Blangko;
         echo form_dropdown('ID_Blangko', $dropdown_Blangko, $selectedBlangko, $atribut_blangko);
     ?&gt;
&lt;/div&gt;

&lt;div class="col-md-6"&gt;
//show the amount in the form input
    &lt;?php echo form_input('Amount', $getAmountfromJS, 'id="amount" class="form-control" readonly="true"') ?&gt;
&lt;/div&gt;
</code></pre>

<p>What I'm trying to do here is when i select a name from the dropdown, the input form will show how much amount from the selected name. How do i do this? Any help will be very much appreciated. Thanks</p>