Estou precisando justamente disso aqui. Preciso que tres selects sejam dependentes um do outro.
Tentei utilizar os cóigos dispomibilizados por vc, mas o segundo select depois de selecionado o primeiro fica apenas em Aguarde... Carregando... e não acontece mais nada.
Será que vc pode me ajudar?
Pagina dos Selects
<?
include("../includes/config.php");
?>
<script language="JavaScript" type="text/JavaScript">
function carregar(){
var url;
url = 'http://localhost/projeto/teste/remote.php?g_servico='+document.Cadastro.g_servico[document.Cadastro.g_servico.selectedIndex].value;
document.Cadastro.especialidade.options.length = 0;
addItem(document.Cadastro.especialidade,"Aguarde...carregando","",false,document.Cadastro.especialidade.length);
myIframe.location = url;
document.Cadastro.especialidade.focus()
}
function inicia(){
local1 = new Array();
var maximo1, i, campo1;
local1 = myIframe.loc;
campo1 = document.Cadastro.especialidade;
maximo1 = local1.length;
document.Cadastro.especialidade.options.length = 0;
addItem(campo1,'Selecione uma especialidade','',false,campo1.length)
for (i=0;i<maximo1;i++)
{
addItem(campo1,local1[i][1],local1[i][0],false,campo1.length);
}
}
function addItem(obj,strText,strValue,blSel,intPos){
var newOpt,i,ArTemp,selIndex;
selIndex = (blSel)?intPos:obj.selectedIndex;
newOpt = new Option(strText,strValue);
Len = obj.options.length+1
if (intPos > Len) return
obj.options.length = Len
if (intPos != Len)
{
ArTemp = new Array();
for(i=intPos;i<obj.options.length-1;i++)
ArTemp[i] = Array(obj.options[i].text,obj.options[i].value);
for(i=intPos+1;i<Len;i++)
obj.options[i] = new Option(ArTemp[i-1][0],ArTemp[i-1][1]);
}
obj.options[intPos] = newOpt;
if (selIndex > intPos)
obj.selectedIndex = selIndex+1;
else if (selIndex == intPos)
obj.selectedIndex = intPos;
}
//cidade
function carregar_cid(){
var url;
url = 'http://localhost/projeto/teste/remote1.php?especialidade='+document.Cadastro.especialidade[document.Cadastro.especialidade.selectedIndex].value;
document.Cadastro.cidade.options.length = 0;
addItem(document.Cadastro.cidade,"Aguarde...carregando","",false,document.Cadastro.cidade.length);
myIframe2.location = url;
document.Cadastro.cidade.focus()
}
function inicia_cid(){
local1 = new Array();
var maximo1, i, campo1;
local1 = myIframe2.loc;
campo1 = document.Cadastro.cidade;
maximo1 = local1.length;
document.Cadastro.cidade.options.length = 0;
addItem(campo1,'Todas as cidades','TODAS',false,campo1.length)
for (i=0;i<maximo1;i++)
{
addItem(campo1,local1[i][1],local1[i][0],false,campo1.length);
}
}
function leapto(Cadastro){
document.Cadastro.submit();
}
</script>
<form name="Cadastro" action="http://localhost/pro...teste/lista.php" target="Cadastro" method="get">
<div style="DISPLAY: none; top:100px; left:100px; position:relative; width:400px; height:20px;">
<IFRAME src name="myIframe" id="myIframe" width="400" height="100" marginwidth="0" marginheight="0"></IFRAME>
</div>
<div style="DISPLAY: none; top:0px; left:-1px; position:relative; width:400px; height:20px;">
<IFRAME src name="myIframe2" id="myIframe2" width="400" height="100" marginwidth="0" marginheight="0"></IFRAME>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<p class="textoTitulo" align="left">Grupo de Serviços:<br>
<select name="g_servico" style="WIDTH:230" onChange="carregar();">
<option value="">Selecione um Serviço</option>
<?php
$sql = mysql_query("SELECT * FROM wss2_cidades GROUP BY estado_cidade ORDER BY nome_estado_cidade");
while($linha=mysql_fetch_array($sql))
{
echo "<option value=\"" . $linha["estado_cidade"] . "\">" . $linha["estado_cidade"] . "</option>";
}
?>
</select><br> <br>
Especialidades:<br>
<select name="especialidade" style="WIDTH:230" onChange="carregar_cid();">
<option value="">Selecione a Especialidade</option>
</select><br> <br>
Cidade:<br>
<select name="cidade" style="WIDTH:230">
<option value="TODAS">Todas as cidades</option>
</select>
</p>
<p><input type="submit" name="Submit" value=" Pesquisar " onClick="java script:Abrir();"></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
Pagina Remote
<?php
include("../includes/config.php");
//configurações de bando de dados
$g_servico = $_GET['g_servico'];
$auxsql = "SELECT * FROM wss2_cidades WHERE estado_cidade='{$g_servico}' ORDER BY nome_cidade";
//$auxsql = "SELECT DISTINCT especialidade FROM cm_convenio WHERE g_servico='{$g_servico}' ORDER BY especialidade ASC";
$sql = mysql_query($auxsql);
if(!$sql){echo mysql_error();exit();}
echo "";
?>
<script>
loc = new Array(<?=mysql_num_rows($sql)?>)
for (i=0; i < <?=mysql_num_rows($sql)?>; i++) {
loc[i] = new Array(2)
for (j=0; j < 2; j++) {
loc[i][j] = "0"
}
}
<? $j = 0;
while ($linha = mysql_fetch_array($sql)) {?>
loc[<?=$j?>][0] = "<?=$linha[0]?>";
loc[<?=$j?>][1] = "<?=$linha[0]?>";
<?$j++;
}
?>
parent.inicia();
<?
mysql_close($dbh);
?>
</script>
Não alterei nada em seu código a não ser as URLs e os dados do banco de dados.
Aguardo respostas