Welcome Guest, Not a member yet? Register   Sign In
Repopulate dropdown
#1

Hi bros,
plz, can anyone tell me how to repopulate the second dropdown after I select the first dropdown?
the first dropdown takes data from DB
tbl.warehouse -> id |code|name|is_active
tbl.rack->rack_id|warehouse_id|name
I'm getting the data for the warehouse, now I want to choose from options on the second dropdown of corresponding to the right warehouse
Reply
#2

codeigniter how to populate second dropdown list based on the first one using codeigniter

Just convert it to CodeIniter 4.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(10-12-2021, 01:24 AM)InsiteFX Wrote: codeigniter how to populate second dropdown list based on the first one using codeigniter

Just convert it to CodeIniter 4.

Maybe im missing something but here is my code for drop down population. Plz any ideas?

//Get rack from warehouse
    public function get_rack_by_warehouse($id){
        $rack = $this->warehouse_model->get_rack_by_warehouse($id);
            foreach($rack as $key => $r){
                echo '<option value="'.$r['rack_id'].'">'.$r['name'].'</option>';
            }
   
    }


On view i have this code:

<script type="text/javascript">

function get_rack(warehouse_id){
    $.ajax({
        url:        '<?php echo base_url();?>warehouse/function get_rack_by_warehouse/' + warehouse_id,
        success:    function(response){
            jQuery('#rack_id').html(response);
        }

    });
}

</script>
Reply
#4

Take 30 seconds to re-read your code:
PHP Code:
<?php echo base_url();?>warehouse/function get_rack_by_warehouse/' + warehouse_id, 
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#5

(10-16-2021, 07:22 AM)includebeer Wrote: Take 30 seconds to re-read your code:
PHP Code:
<?php echo base_url();?>warehouse/function get_rack_by_warehouse/' + warehouse_id,

It's not the typo here
Droptdon is not populated and added class style="display: none;"

<div class="mt-3">
<label for="crud-form-2" class="form-label">Rack</label>
<div class="select">
 <select class="tail-select w-full" id="rack_id" name="rack_id" style="display: none;" data-select-hidden="0" data-tail-select="tail-5"><option value="1">Rack 01</option><option value="2">Rack test 02</option></select>
 <div class="tail-select w-full active" tabindex="0"><div class="select-label"><span class="label-inner">Choose Rack</span></div><div class="select-dropdown" style="max-height: 40px; height: auto; display: block; overflow: visible;"><div class="dropdown-inner" style="max-height: 40px;"><ul class="dropdown-optgroup" data-group="#"><li class="dropdown-option selected" data-key="Choose Rack" data-group="#">Choose rack</li></ul></div></div></div></div>
 </div> 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB