Select Que Altera Um Segundo - Javascript
#1
Posted 24/11/2005, 07:00
function load1(){
var url;
url = 'index_mexer.php?UF='+document.Section.UF[document.Section.UF.selectedIndex].value;
document.Section.SubSec.options.length = 0;
addItem(document.Section.SubSec,"Wait...loading","",false,document.Section.SubSec.length)
myIframe.location = url;
//document.Section.SubSec[document.Section.SubSec.selectedIndex].focus()
}
//////////////i don't know why is not putting the selected option on focus after loading the 2 others select's
function start_sub(){
local1 = new Array();
var maximo1, i, campo1;
local1 = myIframe.loc;
campo1 = document.Section.SubSec;
maximo1 = local1.length;
document.Section.SubSec.options.length = 0;
addItem(campo1,'-Choose one-','',false,campo1.length);
for (i=0;i<maximo1;i++){
addItem(campo1,local1[i][1],local1[i][0],false,campo1.length);
}
}
function load2(){
var url2,url3;
url2= 'index_mexer.php?SubSec='+document.Section.SubSec[document.Section.SubSec.selectedIndex].value;
document.Section.D2.options.length = 0;
addItem(document.Section.D2,"Wait...loading","",false,document.Section.D2.length)
my2frame.location = url2;
// document.Section.D2.focus()
}
function start_key(){
local2 = new Array();
var maximo2, k, campo2;
local2 = my2frame.loc2;
campo2 = document.Section.D2;
maximo2 = local2.length;
document.Section.D2.options.length = 0;
for (k=0;k<maximo2;k++){
addItem(campo2,local2[k][1],local2[k][0],false,campo2.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;
}
</script>
Bom dia a tod@s!
tenho um problema que ja se arrasta a alguns dias... de um select onchange influencia o segundo e este por sua vez onchange influencia um terceiro. A questao e que quando faz o load no fim o campo selecionado do segundo volta sempre a "choose one" ---- addItem(campo1,'-Choose one-','',false,campo1.length);
Queria que este select mantivesse seleccionado o campo que escolhi...mas volta sempre ao "choose one" no load do 3o select. why????
#2
Posted 25/11/2005, 16:58
Eu utilizei um código praticamente igual e ele mantem a escolha do visitante em todos os selects:
Se quiser conferir:
function carregar() { var url; url = '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; }onde:
g_servico - é o nome do select que traz o conteúdo a ser pesquisado no banco
Cadastro - é o nome do form
especialidade - é o nome do select seguinte
Espero que ajude
Fórum WMO - Conselheira - Na equipe desde 31/01/2006.
Links importantes: Regras de conduta - Busca do fórum
#3
Posted 29/11/2005, 07:05
.. ao fazer depender outro (...2) select do segundo, o terceiro depois de carregar deixa o segundo com a opcao ---choose one--- deixando de ficar selecionado o campo em que cliquei. com apenas dois selects funciona na maior...mas assim
de qualquer forma muito obrigado regina!!
#4
Posted 29/11/2005, 13:13
No script que eu utilizei tb são 3 selects, e as opções do visitante ficam em todas as selects.
No código que postei anteriormente basta criar mais uma vez da mesma forma somente alterando as opções, campos.
Da uma olhada neste link
Abaixo tem a imagem das seleções:
Edição feita por: Andreia Regina, 29/11/2005, 18:20.
Fórum WMO - Conselheira - Na equipe desde 31/01/2006.
Links importantes: Regras de conduta - Busca do fórum
#5
Posted 30/11/2005, 13:12
ja consegui finalmente... teimei sempre em nao criar os ficheiros remote.php e acho que foi por isso.
Muito obrigado! gracas a voce tive coragem pra voltar a pegar naquilo e agora ja esta bom...
#6
Posted 30/11/2005, 13:26
Não sei se haveria outra forma de fazer!
Fico contente que esteja resolvido e que tenha ajudado
Fórum WMO - Conselheira - Na equipe desde 31/01/2006.
Links importantes: Regras de conduta - Busca do fórum
#7
Posted 30/11/2005, 14:37
Edição feita por: fmassola, 30/11/2005, 15:02.
#8
Posted 01/12/2005, 09:28
O código para pegar os dados do primeiro select estão acima, no arquivo remote.php vc terá:
<?php //configurações de bando de dados $g_servico = $_GET['g_servico']; $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>
Para o segundo select passar informações ao terceiro basta criar mais uma função e alterar os campos, chamando o arquivo remote1.php por exemplo.
Qualquer dúvida poste novamente
Andreia Regina
Fórum WMO - Conselheira - Na equipe desde 31/01/2006.
Links importantes: Regras de conduta - Busca do fórum
#9
Posted 01/12/2005, 09:43
MTO obrigado
#10
Posted 01/12/2005, 09:52
grato.
#11
Posted 01/12/2005, 17:32
Fabio vou te passar os arquivos para o seu e-mail qualquer coisa posta novamente ok?
Fórum WMO - Conselheira - Na equipe desde 31/01/2006.
Links importantes: Regras de conduta - Busca do fórum
#12
Posted 01/12/2005, 21:03
#13
Posted 30/01/2006, 14:48
fico no Aguardo
Abraços
#14
Posted 30/01/2006, 14:56
Aí vai:
<script language="JavaScript" type="text/JavaScript"> function carregar() { var url; url = ''http://www.dominio.com.br/admin/includes/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://www.dominio.com.br/admin/includes/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>Vou te passar o formulário tb:
<form name="Cadastro" action="http://www.sisflex.com.br/aspp/admin/includes/objetos/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 DISTINCT g_servico FROM cm_convenio GROUP BY g_servico ORDER BY seq ASC"); while($linha=mysql_fetch_array($sql)) { echo "<option value=\"" . $linha["g_servico"] . "\">" . $linha["g_servico"] . "</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="javascript:Abrir();"></p> </td> </tr> </table> </td> </tr> </table> </form>
Nossa fiz este formulário ainda usando tabelas rs
$g_servico = $_GET['g_servico']; $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>
o segundo (remote1) é basicamente igual só mudam os nomes dos campos
Qualquer coisa volta a postar!
Fórum WMO - Conselheira - Na equipe desde 31/01/2006.
Links importantes: Regras de conduta - Busca do fórum
#15
Posted 10/05/2006, 21:05
Já consegui fazer.. desculpa ae qualquer coisa....
Abraços!
Edição feita por: ChronosZin, 11/05/2006, 09:41.
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)