Good morning Programmers .. I need a favor, next I have a combobox that is generated through a select until then everything ok .. I need to receive this item selected by the user and save the information because in the next combobox I use this information, ie I use this selected item in a select ... the business is the following has several companies with several branches each, when the user select the company from it, I want the next combobox to appear in the selected company, it's all going to be in compliance. I just have to save the selected information ... follow the codes:
<select size="1" name="Empresa" id="Empresa" onchange="opcao()">
<option selected value="Selecione">Empresa </option>
<?php
for($x=0;$x<count($resposta2);$x++)
{
echo '<option value= "'.$resposta2[$x][0].'">'.$resposta2[$x][1].' </option>';
}?>
</select>
<p></p>
<select size="1" name="Unidade">
<option selected value="Selecione">Unidade</option>
<?php
for($x=0;$x<count($resunid);$x++)
{
echo '<option value= "'.$resunid[$x][0].'">'.$resunid[$x][1].' </option>';
}?>
</select>
At first as I already have all system companies, I need that in the onchange where I call a js, be saved the selected item and use in the function call follows the js
<script type="text/javascript">
function opcao(){
var x = document.getElementById("Empresa").selectedIndex;
var endereco = document.getElementById("Empresa").options[x].value;
if (endereco != "#")
{
var $unid = document.getElementById("Empresa").value;
window.location = "totalpago.php?parametro=$unid"
alert($unid);
}
</script>
After saving the selected item need to assign this item in the function below
function todasunidades()
{
include("conexao.php");
if (!conectaBancoDados()) {
$resposta2 = "<center><b>Não foi possível estabelecer conexão com o Banco de Dados!</b></center>";
}
else
{
$comandoSql = "SELECT Cod_UC, UC FROM Tab_UC where Cod_Empresa="; é aqui que preciso usar o item selecionado...
$dados = mysql_db_query($bancoDados, $comandoSql) or die (mysql_error());
$x=0;
while ($linha = mysql_fetch_array($dados))
{
$resunid[$x][0] = $linha["Cod_UC"];
$resunid[$x][1] = $linha["UC"];
$x++;
}
}
return $resunid;
}
and in company_code, I need to use the selected item .. if anyone tried and could help me thank you