CodeIgniter Forums
how to use Ajax with CodeIgniter in a combo box - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how to use Ajax with CodeIgniter in a combo box (/showthread.php?tid=24254)



how to use Ajax with CodeIgniter in a combo box - El Forum - 11-04-2009

[eluser]ranjitbd[/eluser]
Code:
// in my view page a combo box where the local city name is present.
    <select name="city" id="city" class="textBoxStyle" style="width:100">
            <option value="">Select One</option>
            <option value="all">All</option>
                &lt;?php
                  foreach ($package_name as $destination){?&gt;
                    <option value="&lt;?php echo $destination['id'];?&gt;">&lt;?php echo $destination['city_name'];?&gt;
            </option>
                &lt;?php } ?&gt;
       </select>

// and a radio button that is
    &lt;input name="holiday_type" type="radio" value="2"/&gt;International Holiday
// when the user will click on the radio button the combo box will show the international
//city_name from the database using ajax..

// i dnt know how to execute ajax with codeigniter but i can do it using raw php.



how to use Ajax with CodeIgniter in a combo box - El Forum - 11-04-2009

[eluser]Ben Edmunds[/eluser]
There are many different ways. Look up using an ajax request. You would do an ajax request to a controller that would return back the city name.


how to use Ajax with CodeIgniter in a combo box - El Forum - 11-04-2009

[eluser]Berserk[/eluser]
your controller :
Code:
function get_cities(){
$cities = $model->get_cities();
echo json_encode(array('status'=>'1','cities'=>$cities));
}
your js (jQuery) function:
Code:
function get_cities(){
$.post(your_controller_url,{postdata:postdata},function(data){
   if(data.status==1){
     // print your view here
   }
},'json');
};