0
Good morning Programmers.. I need a favor, next I have a combobox that is generated through a select so far 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, that is, I use this item selected in a select... the business is the following has several companies with various branches each, when the user selects his company, I want that in the next combobox appear the affiliates of the selected company, ta everything going in the conforms only I have to save this information selected... follows 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>
In the 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 called follow 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 you need to assign that item no 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 cod_company, I need to use the selected item.. if someone intended and can help me thank you