Jump to content


Photo

Atualizar Combos Sem Recarregar Pagina


  • Faça o login para participar
4 replies to this topic

#1 thescente

thescente

    Eron Venter

  • Usuários
  • 599 posts
  • Sexo:Não informado
  • Localidade:Novo Hamburgo/RS

Posted 22/11/2005, 15:44

boa tarde!

seguinte eu tenho 2 combos na minha pagina, marca e modelo ambos carregam dados de um banco/tabela.

mas assim, ao selecionar a marca, a pagina atualmente recarrega dai o combo modelo vem com os modelos daquela determinada marca...

eu queria fazer isso sem recarregar a pagina é possivel?

#2 bdoweb

bdoweb

    Super Veterano

  • Usuários
  • 1641 posts
  • Sexo:Masculino
  • Localidade:São Paulo - SP

Posted 22/11/2005, 16:29

<html>
<head>
<title>Documento sem t?lo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?
$conexao = mysql_connect("HOST","USER","SENHA")
      or die("Configurações erradas. Tente novamente!");
//selecionando o banco de dados
$db = mysql_select_db("BANCO")
  or die ("Banco de dados inexistente");
$sql = mysql_query("SELECT DISTINCT CAMPO FROM TABELA order by CAMPO PARA ORDENAR ASC"); 
?>
<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">
UF:<br><select name="UF" onChange="carregar();">
<option value="">--UF--</option>
    <?
    while($linha=mysql_fetch_array($sql)) {
    echo "<option value=\"" . $linha["state"] . "\">" . $linha["state"] . "</option>";
    }
    ?>
</select><br>
Cidades:<br><select name="Cidades"></select>
</form>
<?
mysql_close($con);
?>
</body>
</html>
pagina remote.php
<?
$conexao = mysql_connect("HOST","USER","SENHA")
      or die("Configurações erradas. Tente novamente!");
//selecionando o banco de dados

$db = mysql_select_db("BANCO")
  or die ("Banco de dados inexistente");
$UF = $_GET['UF'];
$auxsql = "SELECT DISTINCT CAMPO FROM TABELA WHERE state='{$UF}' order by CAMPOS PARA ORDENAR";
$sql = mysql_query($auxsql);
if(!$sql){echo mysql_error();exit();}
?>
<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($con);
?>
</script>

Se quiser ver como funcional http://www.capesp.co...ste_refresh.php


[]'s
Quer ajuda seus amigo e ainda ganhar uma graninha?
Acesse agora mesmo http://yeapiz.com

#3 thescente

thescente

    Eron Venter

  • Usuários
  • 599 posts
  • Sexo:Não informado
  • Localidade:Novo Hamburgo/RS

Posted 22/11/2005, 17:25

bah, show de bola isso cara, parabens e vlw ai :)

#4 mysteriouspy

mysteriouspy

    Normal

  • Usuários
  • 114 posts
  • Sexo:Não informado

Posted 02/03/2006, 19:46

cara...vc teria essas cidades pra me arranjar??
tlvz a tabela do bd e talz...

vlww

#5 Tx.NET

Tx.NET

    || ||||||| ||| ||||||||

  • Banidos
  • PipPipPipPipPipPipPip
  • 619 posts
  • Sexo:Não informado

Posted 06/03/2006, 09:38

www.google.com
> ls -la
-rwxr-xr-- 1 fmaynnard user 9666 nov 28 00:00 hell

> shutdown -h now




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq