2
I am making two elements Select a "Area" and another "Problem" and I need to relate to each other, in the BD table of the problem FK spr_sar_codigo referring to sar_codigo of the table Area. I am unable to interact so that the select problem depends on what is selected in the area. Here are the two Controller methods to load the two selects:
public function ajaxcarregaarea() {
    $obj_area = new daoArea();
    $areas = $obj_area - > Consultar();
    $select = "<select id='area' name='area' data-obrigatorio='S' class='valido'>";
    $select. = "<option value='' selected='selected'>Selecione a área responsável</option>";
    foreach($areas as $area) {
        $select. = "<option value='".$area['sar_codigo'].
        "'>".$area['sar_titulo'].
        "</option>";
    }
    $select. = "</select>";
    echo $select;
}
public function ajaxcarregaproblema() {
    $obj_problema = new daoProblema();
    $problemas = $obj_problema - > Consultar();
    $select = "<select>";
    $select. = "<option value='' selected='selected'>Selecione a área responsável</option>";
    foreach($problemas as $problema) {
        $select. = "<option value='".$problema['spr_sar_codigo'].
        "'>".$problema['spr_problema'].
        "</option>";
    }
    $select. = "</select>";
    echo $select;
}
And here’s the corresponding Divs and what I did in Script in the file where the Divs are:
<div class="row">
    <div class="col-xs-4 col-xs-offset-1 cfd">
        <?=$i->getFormularioIdioma("Área Responsável")?>:
    </div>
    <div id="areas" class="col-xs-6 cfb so-awesome1">
    </div>
</div>
<div class="row">
    <div class="col-xs-4 col-xs-offset-1 cfd">
        <?=$i->getFormularioIdioma("Qual o Problema")?>:
    </div>
    <div id="problemas" class="col-xs-6 cfb so-awesome2">
    </div>
</div>
$(document).ready(function() {
    $.post("<?=$url?>insuporte/abrirchamado/ajaxcarregaarea", {}, function(ajaxcarregaarea) {
        $('#areas').html(ajaxcarregaarea);
    });
});
I don’t know how to create this relationship, I know I need to use the jquery onchange event but I had no idea how to do, I’m still beginner and esytou with many difficulties.
Thank you very much, I understand but you still haven’t helped me but thanks for the time available.
– user53616