I am making two elements Select an "Area" and another "Problem" and need to relate to each other, in the problem DB table is the FK spr_sar_code referring to the sar_code of the Area table. I am not able to interact so that the select problem depends on what is selected in the area. Here are the two methods of the Controller 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 are the corresponding divs and what I did in the 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 do not know how to create this relationship, I know that I need to use the onchange event of jquery but I had no idea how to do it, I'm still a beginner and it was very difficult.