The next problem is that when a person selects an option of a select, the value of that chosen option is obtained and stored within a php variable.
Here I get the Id of the selected option.
It occurs to me, for example, to use done or success in js when successfully passing the variable from js to php within the same page, to execute the PHP code below but I do not know how it would be .
<script>
$(document).ready(function() {
$("#nivel-especialidad").change(function() {
$("#nivel-especialidad option:selected").each(function ejecutar() {
Id_nivel = $(this).val();
$.post(Id_nivel);
//OBTENER EL ID DE LA OPCION SELECCIONADA
//ASIGNANDOLO A UNA VARIABLE PHP MAS ABAJO
$("#requisitos-especialidad").load();
// ESTE CODIGO PIENSO QUE IRIA DENTRO DEL SUCCESS O DONE DE JS
// PARA PODER EJECUTAR EL CODIGO PHP DE ABAJO
// QUE ESTA DENTRO DE UN DIV
});
})
});
</script>
The following PHP code corresponds to the one I want to execute after the PHP variable gets the ID_NIVEL:
<?php
$id_nivel = $_POST['Id_nivel'];
//AQUI GUARDARIA EL VAR ID_NIVEL DE JS PARA PASARLO EN LA SIGUIENTE LINEA
?>
<table class="table table-bordered">
<tbody>
<div id="requisitos-nivel" name="requisitos-nivel">
<?php
//ESTE ES EL CODIGO QUE QUIERO EJECUTAR DE FORMA DINAMICA CUANDO SE OBTENGA EL ID_NIVEL DENTRO DE LA VARIABLE PHP
$requisitos = DAORequisito :: consultarRequisitosPorIdNivel(Conexion :: obtenerConexion(), $id_nivel);//CONSULTA A LA BD
echo "<tr>";
for ($i = 0, $contador=1; $i < count($requisitos); $i++, $contador++) {?>
<td>
<div class="card" style="width: 20rem;">
<!--<img class="card-img-top" src="..." alt="Card image cap">-->
<div class="card-body">
<p class="card-text"><?php
echo $requisitos[$i] -> obtenerTexto();
?></p>
<input type="checkbox">
</div>
</div>
</td>
<?php if(($contador%3) == 0) {
echo "</tr><tr>";
}
}
echo "</tr>";
?>
</div>
</tbody>
</table>