No consigo hacerlo funcionar.
El codigo html lo tengo así:
Código HTML:
<body onLoad="document.getElementById('txtSearch').focus()" >
<table width="100%" border="0">
<tr>
<td><div align="center"><a><img src="imagenes/logo_hormiga_erg.png" width="446" height="143" border="0"></a></div></td>
</tr>
</table>
<table width="100%" border="0">
<td><form id="frmSearch" action="consulta.php" method="post">
<div align="center">
<input name="txtSearch" type="text" id="txtSearch" size="45" onkeypress="tuFuncion(ev);" onKeyUp="searchSuggest();" autocomplete="off"/>
<script type="text/javascript">
//<![CDATA[
var elemento = document.getElementById("txtSearch")
elemento.setAttribute("autocomplete", "off");
//]]>
</script>
<input name="cmdSearch" id="cmdSearch" value="Buscar" type="submit"><br />
<div id="search_suggest">
</div>
<div align="center" id="links_bus">
<p align="center"><a href="bus_avan_index.php" class="style1">Búsqueda Avanzada</a> <span class="style1"><a href="bus_rubro_index.php">Búsqueda por Rubro</a></span> <a href="bus_calle_index.php" class="style1" >Búsqueda por Calle</a> <a href="bus_cal_indice_in.php" class="style1">Búsqueda por Indice de Calle</a> <a href="bus_cuadras_index.php" class="style1">Búsqueda por Cuadras</a> <span class="style1"><a href="mapa.php">Búsqueda por Zonas</a></span> </p>
</div>
</form></td>
</body>
y el JS es este:
Código:
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
alert("Tu navegador no es compatible. Intenta usando Mozilla Firefox, Apple Safari o Google Chrome");
}
}
//Our XmlHttpRequest object to get the auto suggest
var searchReq = getXmlHttpRequestObject();
//Called from keyup on the search textbox.
//Starts the AJAX request.
function searchSuggest() {
if (searchReq.readyState == 4 || searchReq.readyState == 0) {
var str = escape(document.getElementById('txtSearch').value);
searchReq.open("GET", 'searchSuggest.php?search=' + str, true);
searchReq.onreadystatechange = handleSearchSuggest;
searchReq.send(null);
}
}
//Called when the AJAX response is returned.
function handleSearchSuggest() {
if (searchReq.readyState == 4) {
var ss = document.getElementById('search_suggest')
ss.innerHTML = '';
var str = searchReq.responseText.split("\n");
for(i=0; i < str.length - 1; i++) {
//Build our element string. This is cleaner using the DOM, but
//IE doesn't support dynamically added attributes.
var suggest = '<div onmouseover="javascript:suggestOver(this);" ';
suggest += 'onmouseout="javascript:suggestOut(this);" ';
suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';
suggest += 'class="suggest_link">' + str[i] + '</div>';
ss.innerHTML += suggest;
}
}
}
//Mouse over function
function suggestOver(div_value) {
div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
div_value.className = 'suggest_link';
}
//Click function
function setSearch(value) {
document.getElementById('txtSearch').value = value;
document.getElementById('search_suggest').innerHTML = '';
}
A ver si ves lo que estoy haciendo mal.
Saludos y gracias