-1
I have a option select
that when selecting an option it goes in BD and returns the value to another option select
, works perfectly.
index with the option select
:
<?php
require './conexao.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>Atualizando combos com jquery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#funcao').change(function () {
$('#tipo').load('listaFuncoes.php?funcao=' + $('#funcao').val());
}).change();
});
</script>
</head>
<body>
<h1>Atualizando combos com jquery</h1>
<label>Função:</label>
<select name="funcao" id="funcao">
<option value="">selecione</option>
<?php
$rs = mysqli_query($conexao, "SELECT * FROM funcao ORDER BY nome");
for ($i = 0; $i < mysqli_num_rows($rs); $i++) {
$linha_funcao = mysqli_fetch_array($rs);
?>
<option value="<?= $linha_funcao[0] ?>"><?php echo $linha_funcao[1] ?></option>
<?php
}
?>
</select>
<br /><br />
<div id="tipo">
</div>
</body>
</html>
and my listaFuncoes.php
where it is fed with the result of the 1st option
:
<?php
require './conexao.php';
$id_estado = $_GET['funcao'];
$select_func = "SELECT DISTINCT tp.idfuncao, tpd.id ,tpd.descricao "
. "FROM tipos_prova tp "
. "INNER JOIN tipos_prova_descricao tpd ON tpd.idDescricao = tp.desctipoprova "
. "WHERE tp.idfuncao = '$id_estado' "
. "ORDER BY tpd.descricao";
$rs = mysqli_query($conexao, $select_func);
echo "<select class='custom-select mb-3' name='tipo' required>
<option value=''>selecione</option>";
for ($i = 0; $i < mysqli_num_rows($rs); $i++) {
$linha_funcao = mysqli_fetch_array($rs);
?>
<option value="<?= $linha_funcao[0] ?>"><?php echo $linha_funcao[2] ?></option>
<?php
}
echo "</select>";
Here comes the problem, now I need a third option select
and receives the values passed from the 1st and 2nd option select
after choosing the option of the 2nd option
, how to solve?
Ex: 1st option passes value=1. 2nd option passes value=3. and in the third option I need these 2 values.
It would not solve, because I need you to send the value of the 1st select next to the 2nd select, type Country/State/City search. he will take the city of the state of that particular country.
– Aristófanes Melo
You can assign to a variable outside the scope the values, it can be even an object, something like 'const Location = { select1: 'Valor3', Select2: 'valor2', select3: 'Valor3' }', and your this.value of each chage will set in the value of the corresponding property of the object.
– Alexandre Vieira de Souza