1
I have an option
<p> Curso:
<select name='curso' id="aparecercurso" class="escolhercursos">
<option>Nenhum</option>
<?
$sqlcursos = "SELECT designacao FROM cursos";
$respostacurso = mysql_query($sqlcursos,$conexao);
while ($curso = mysql_fetch_array($respostacurso))
{
echo "<option> ".$curso['designacao']."</option>";
}
?>
</select>
</p>
And I wanted to use whatever value I chose on this option
to open another one like this:
<p> Disciplina:
<select name='disciplina' required tabindex="9">
<?
$escolha = $_POST['curso'];
$sqltentar = "SELECT d.designacao_disciplina
FROM disciplinas d, disc_curso dc, cursos c
WHERE c.designacao = '".$escolha."'
AND d.cod_disciplina = dc.cod_disciplina
AND dc.n_curso = c.n_curso ";
$respostacurso = mysql_query($sqltentar,$conexao);
while ($rowcurso = mysql_fetch_array($respostacurso))
{
echo "<option> ".$rowcurso['designacao_disciplina']."</option>";
}
?>
</select>
</p>
I just don’t know how to pass the value of the first option
for the next.
I’ve tried how they come up through POST
but I think it would only happen after clicking Ubmit. With javascript it was only take the id of the element but then how to go to PHP again?
We already have solution for this on the site, if you will use JS, the solution is to use AJAX making the JS request the data of a PHP
– Bacco
http://answall.com/search?q=%5Bajax%5D+%5Bphp%5D+select
– Bacco
I try to avoid always using AJAX, because I read in an article, that if I used AJAX for nothing, the site might have problems. But if you have no other suggestion than AJAX..
– programmer2016
Using anything for nothing gives problems (in fact, these are the so-called "good practices", that is, things that are told and repeated without context and are useless). If you want to take data from a PHP without reloading, there is no option left but Ajax. Take advantage of the following link, which has a functional example in the answer that is exactly what you need to do: http://answall.com/questions/26291/popular-combo-com-chamada-de-ajax
– Bacco
I am making this form using bootstrap modals. With ajax updating the page the modal will not close?
– programmer2016
Ajax doesn’t do anything you don’t have it do. It does the request and calls the function you point to perform when changing the state. Your job decides everything else.
– Bacco