Cakephp3 how to refresh a dropdown acording to other dropdown

i’m having a real bad time trying to do this, please someone helpme!

i have this add view where i want to have 2 selectors, eveerytime a select something in one selector, the second selector must update its data.

this is my database and how is it displaying right now

every Empresas hasMany Sucursales

Im trying to this in Ofertas add, so i have this in my controller

public function add()
{
    $tblOferta = $this->TblOfertas->newEntity();
    if ($this->request->is('post')) {
        $tblOferta = $this->TblOfertas->patchEntity($tblOferta, $this->request->data);
        if ($this->TblOfertas->save($tblOferta)) {
            $this->Flash->success(__('The tbl oferta has been saved.'));
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error(__('The tbl oferta could not be saved. Please, try again.'));
        }
    }
    $tblCategorias = $this->TblOfertas->TblCategorias->find('list');
    $tblSucursales = $this->TblOfertas->TblSucursales->find('list');
    $tblEmpresas = $this->TblOfertas->TblSucursales->TblEmpresas->find('list');
    $this->set('tblCategorias', $tblCategorias);
    $this->set('tblSucursales', $tblSucursales);
    $this->set('tblEmpresas', $tblEmpresas);
    $this->set('tblOferta', $tblOferta);
    $this->set('_serialize', ['tblOferta']);
}

and this in my add.ctp view

<nav class="large-3 medium-4 columns" id="actions-sidebar">
    <ul class="side-nav">
        <li class="heading"><?= __('Actions') ?></li>
        <li><?= $this->Html->link(__('List Tbl Ofertas'), ['action' => 'index']) ?></li>
    </ul>
</nav>
<div class="tblOfertas form large-9 medium-8 columns content">
    <?= $this->Form->create($tblOferta) ?>
    <fieldset>
        <legend><?= __('Añadir Oferta') ?></legend>
        <?php
        echo $this->Form->input('nombre');
        echo $this->Form->input('descripcion');
        echo $this->Form->input('nombre_imagen');
        echo $this->Form->input('fecha_creacion');
        echo $this->Form->input('estado_activa');
        echo $this->Form->input('fecha_inicio');
        echo $this->Form->input('fecha_fin');
        echo $this->Form->input('duracion_dias');
        echo $this->Form->input('nombre_encargado');
        echo $this->Form->input('telefono_encargado');
        echo $this->Form->input('email_encargado');
        echo $this->Form->input('tbl_categoria_id', ['options' => $tblCategorias]);
        echo $this->Form->input('empresas', ['options' => $tblEmpresas]);
        echo $this->Form->input('tbl_sucursales._ids', ['options' => $tblSucursales]);
        ?>
    </fieldset>
    <?= $this->Form->button(__('Submit')) ?>
    <?= $this->Form->end() ?>
</div>

every time a select an Empresa, Sucursales must update its data, “every Empresa hasMany sucursales”

Hmm, I’m not 100% sure if I understand your question completely, but normally you’d need to use Javascript / Ajax to update a select field dynamically.

So you may either load all the child select fields on page load, hide them, and when selecting an option in the parent select field, show the appropriate child select.

Or you may load the child select dynamically via ajax every time you select something in the parent field.

I actually think that these are basically the only two possible ways to achieve this.

i did something like this in one of my projects. I implemented it with the jquery $('selector;).on(‘change’,function (event ) { event to execute});. I hope it will help you. Tell me if you still don’t know how to implement it .

I need some guidance about it. Can you tell me how can I achieve it (I think I need two actions in a controller and also the jquery on the view, but I’m currently stuck with it).

Thank you in advance.