Ver Mensaje Individual
  #11 (permalink)  
Antiguo 27/01/2010, 08:22
javitineo
 
Fecha de Ingreso: abril-2006
Mensajes: 54
Antigüedad: 18 años
Puntos: 1
Respuesta: autocomplete con jquery

HTML:
Municipio: <input type="text" id="municipio" name="municipio" '.$disabled.' size="30" value="'.$_REQUEST['municipio'].'" />
<span class="calle">Calle:</span> <input type="text" id="calle" name="calle" size="30" />

EL SCRIPT:
<script type="text/javascript">
jQuery().ready(function() {

jQuery("#calle").autocomplete("centros/BuscadorCalles.php?municipio='.$_REQUEST['municipio'].'",
{minChars: 1,
max:25,
width: 200,
highlight: false,
scroll: false,
scrollHeight: 300,
matchContains: true,
autoFill: true,
formatItem: function(row, i, max) {return row[0];}
});
jQuery("#municipio").autocomplete("centros/BuscadorMunicipios.php",
{minChars: 1,
max:25,
width: 200,
highlight: false,
scroll: false,
scrollHeight: 300,
matchContains: true,
autoFill: true,
formatItem: function(row, i, max) {return row[0];}

</script>

Y EL PHP DE UNO DE LOS AUTOCOMPLETE (el lotro es similar)

<?php
//Buscador que devuelve un listado de zonas a partir de una parte de su nombre. Usado por los "textbox" para autorrellenarse
include ("comun/agente_mysql.inc");
$agenteSQL = new agente_bd_work("auth/datos.txt");

//El autorrellenar siempre nos indica en el parámetro "q" lo que ha escrito el usuario
$q = strtolower($_GET["q"]);

if (!$q) return;

//Preparamos la consulta SQL
$queryOriginal = "
SELECT distinct viapobla as calle FROM codpostales ";


$queryOriginal .= " co inner join centros c on c.codlocalidad=co.codlocalidad
inner join codigosmunicipios m on m.codmunicipio=c.codmunicipio and descripcion='".$_REQUEST['municipio']."'";

$queryOriginal .= " where viapobla not like '%CODIGO%' and viapobla like '%".$q."%' order by viapobla";

$queryFinal = $queryOriginal;

$resultado=$agenteSQL->ejecutaselectbucleUNACONSULTA($queryFinal);

while ($row = mysql_fetch_array($resultado) )
{
$calle=$row['calle'];

echo "$calle\n";
}//Fin del WHILE


?>