Welcome Guest, Not a member yet? Register   Sign In
how to use Ajax with CodeIgniter in a combo box
#1

[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.
#2

[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.
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB