Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

xidodemisar

Combo de estado e cidades

Recommended Posts

E ai turma blza?

estou tentando fazer um combo onde você seleciona o estado, as cidades são selecionadas automaticamente.

Porém eu não consigo fazer com que as cidades sejam carregadas

apenas aparece a mensagem: "Aguarde---Carregando".

Eu acho que a função do javaScript esteja incorreta .

Alguém pode me ajudar??

 

 

esse e o código

<?phpinclude("conecta.php");$sql = mysql_query("SELECT * FROM estado");?><script language="JavaScript" type="text/JavaScript">function carregar(){var url;url = 'remote.php?UF='+document.Cadastro.UF[document.Cadastro.UF.selectedIndex].value;document.Cadastro.Cidades.options.length = 0;addItem(document.Cadastro.Cidades,"Aguarde...carregando","",false,document.Cadastro.Cidades.length)myIframe.location = url;document.Cadastro.Cidades.focus()}function inicia(){local1 = new Array();var maximo1, i, campo1;local1 = myIframe.loc;campo1 = document.Cadastro.Cidades;maximo1 = local1.length;document.Cadastro.Cidades.options.length = 0;addItem(campo1,'TODAS','',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;}</script></head><body><div style="DISPLAY: none; POSITION: absolute" align="left"><IFRAME src name="myIframe" id="myIframe" width="400" height="100" marginwidth="0" marginheight="0"></IFRAME></div><form action="remote.php" method="post" name="Cadastro"> <table width="800" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFF66">   <tr>	 <td height="144" colspan="3"><center> <div align="center">Estados:<br>		 <select name="UF" onChange="carregar();">		   <option value="">--UF--</option>		   <?php   while($linha=mysql_fetch_array($sql)) {   echo "<option value=\"" . $linha["codigo"] . "\">" . $linha["nome"] . "</option>";   }   ?>		 </select>		 <br>		 Cidades:<br>		 <select name="Cidades">		 </select>	   </div></td>	 <p> </tr>   <tr>	 <td> </td>	 </form>cidades<?phpinclude("conecta.php");$UF = $_GET['UF'];$auxsql = "SELECT * FROM cidade where estado_codigo =$UF ";$sql = mysql_query($auxsql);if(!$sql){echo mysql_error();exit();}?><script language="JavaScript" type="text/JavaScript"><!-- OnLoad="java script:carregar();"-->  loc = new Array(<?php=mysql_num_rows($sql)?>)  for (i=0; i < <?php=mysql_num_rows($sql)?>; i++) {		 loc[i] = new Array(2)				 for (j=0; j < 2; j++) {			 loc[i][j] = "0"		   }   }   <?php $j = 0;	 while ($linha = mysql_fetch_array($sql)) {?>	  loc[<?php echo=$j?>][0] = "<?php echo=$linha[0]?>";	  loc[<?php echo=$j?>][1] = "<?php echo=$linha[1]?>";	  <?php$j++;	  }   ?>   parent.inicia();<?phpmysql_close($conn);?></script>

valeu!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.