Welcome Guest, Not a member yet? Register   Sign In
Choosing a chained select option with jquery using Codeigniter

(This post was last modified: 10-10-2022, 03:47 AM by JiwanFilembar.)

I'm not much good at jquery and ajax, and I'm now having difficulties on a select box. I use CI and My code is below.

Another select box "category" data will be show according to the "brand". How can I carry data from "brand" and show data in "category" with jquery?


<select name="brand" class="form-control" id="brand" required>
        if($items) {
            foreach($items as $key) {
    <option value="<?php echo $key->brand_id ?>">
        <?php echo $key->brand_name ?>

<select name="category" class="form-control" id="category" required>


    $(function() {
        $("#brand").on('change', function() {
            var brand = $(this).val();
            $.ajax ({
                type: "post",
                url: "<?php echo base_url(); ?>receiving/showCategory",
                dataType: 'json',
                data: 'brand='+brand,

                success: function(msg) {
                    var options;
                    for(var i = 0; i<msg.length; i++) {
                        options = '<option>'+msg.category[i].category_name+'</option'>;

function showCategory() {
    $brand_id = $this->input->post('brand');
    $data['category'] = $this->item_model->category($brand_id);
    echo json_encode($data);
My category table omegle shagle voojio contains: category_id, category_name, brand_id.

Theme © iAndrew 2016 - Forum software by © MyBB