Welcome Guest, Not a member yet? Register   Sign In
Update Dropdown Options based on User Input in View
#3

(03-17-2016, 04:06 AM)InsiteFX Wrote: You will need to use javascript to do this, here is the link to one.

Update Dropdown Listbox

PHP Way:

PHP Dropdown Listbox

Thanks for reply, I have tried to get the same through jquery, but I didn' get the result here is my code:

Here is my View:
Code:
<option value='' selected>--Select--</option>
    <option value="4">Bilaspur</option>
    <option value="3">Kinnaur</option>
    <option value="6">Mandi</option>
    <option value="1">Shimla</option>
    <option value="2">Solan</option>
    <option value="5">Una</option>
</select>
<select name="city" id="city"></select>

JAVASCRIPT:
Code:
<script>
    $('#district').change(function(){
        $.getJSON(
            '"<?php echo base_url(); ?>check/data',
            'district='+$('#district').val(),
            function(result){
                $('#city').empty();
                alert(result);
                $.each(result.result, function(){
                    $('#city').append('<option>'+this['city']+'</option>');
                });
            }
        );
    });
</script>

CONTROLLER:
Code:
class Check extends Admin_Controller {

    function __construct()
    {
        parent::__construct();

        $this->load->model('check_m');
    }

    public function data($check){

        $data = $this->check_m->get_city(array('district' => $check), TRUE);
        echo json_encode(array('result'=>$data));

    }
}

MODEL:
Code:
public function get_city($where){
    $this->db->where($where);
    return $this->db->get('citys');
}


Kindly help me? and tell me where I am doing wrong.


Thanks.
Reply


Messages In This Thread
RE: Update Dropdown Options based on User Input in View - by manojrhr - 03-22-2016, 10:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB