Ver Mensaje Individual
  #10 (permalink)  
Antiguo 04/12/2007, 08:28
sciutomaxi
 
Fecha de Ingreso: junio-2007
Mensajes: 152
Antigüedad: 16 años, 11 meses
Puntos: 0
Re: Clone Google Suggest

Cita:
Iniciado por B** Ver Mensaje
Mmmmmm sigo con algunas dudas.. mira yo tengo un suggest y funciona.. pero el usuario tiene que ir al resultado con el mouse.. y en tu ejemplo, me diste ya unos resultados ...
Mira.. te muestro mi ejemplo, y haber si me puedes ayudar un poco para como poder adaptar tu ejemplo al mio.. :S por q tengo q mostrarlo para un proyecto final..
[php]
Código HTML:
<html><head>
<script language="javascript">
                    function nuevoAjax(){
                    var xmlhttp=false;
                     try {
                      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                     } catch (e) {
                      try {
                       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                      } catch (E) {
                       xmlhttp = false;
                      }
                     }

                    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                      xmlhttp = new XMLHttpRequest();
                    }
                    return xmlhttp;
                    }

            function carga()
                    {
                        var contenedor;
                        var otro;
                        var url;
                        url='bd_suggest.php?Buscar='+document.getElementById('Buscar').value;
                          ajax=nuevoAjax();

                          ajax.onreadystatechange=function() {
                           if (ajax.readyState==4 && ajax.status==200 ) {
                            suggest.innerHTML = ajax.responseText;
                              }
                            }
                               if(document.getElementById('Buscar').value != ''){
                        	       document.getElementById('suggest').style.display='';
                            	   document.getElementById('suggest').innerHTML='';
                                   ajax.open("GET",url,true);
                                   ajax.send(null)

                                }

                               else
                                    {
                        	       	document.getElementById('suggest').style.display='none';
                                    document.getElementById('suggest').innerHTML='';
                             	}
                    }



                        function Get(val){
                            document.getElementById('Buscar').value	= val;
                            document.getElementById('Buscar').focus();
                        	document.getElementById('suggest').style.display='none';
                            document.getElementById('suggest').innerHTML='';

                        }


</script>
<style>
div#suggest{
	font:verdana;
	border-width: 1;
	border-style: solid;
	border-color: #D1D7DC;
	background-color: #E8E8E8;
}
a:hover{
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size: 10px;
	list-style-type: none;
	cursor: pointer;
	background-color: #FFFFFF;
	width: 100%;
	display: block;
	text-decoration: none;
}
p{
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size: 10px;
	list-style-type: none;
	cursor: pointer;
	background-color: #E8E8E8;
	width: 100%;
}
a {
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size: 10px;
	list-style-type: none;
	cursor: pointer;
	background-color: #E8E8E8;
	width: 100%;
	display: block;
	text-decoration: none;
}
</style>
</head>
<title>Suggest</title>
<body>
<center>
<table>

  <tr>
   <td>
    <form name="form1">
    <input type="text" name="Buscar"  id="Buscar" size="50" AUTOCOMPLETE=OFF onKeyUp="carga();">
    <div id="suggest" style="display:none"></form>
    </div>
    <td>
   </tr>

</table>
</center>
<body> 
Código PHP:
<?php
            $servidor
"localhost";
            
$bd "prueba";
            
$user "root";
            
$pass "pass";

            
$con mysql_connect($servidor,$user,$pass) or die(mysql_error());
            
mysql_select_db($bd,$con)or die("Error".mysql_error());

            
$q $_GET['Buscar'];
            
$SQL="Select usuario from nombres where usuario Like '$q%'";
            
$res mysql_query($SQL,$con);
            
$row mysql_fetch_array($res);


           do{

             echo 
"<P><a href='javascript:' OnClick=\"Get('".$row[0]."')\">".$row[0]."</a></P>";


            }
            while(
$row mysql_fetch_array($res));
            
?>
Gracias de antemano..
Amigo la verdad que quiero hacer algo asi lo unico entro a tu pagina pero ese buscador no anda si el de google lab esta muy bueno me pasas los codigos de como lo hace google lab gracias