siento abundar en este tema que ya se ha tocado aquí, pero no he podido realizarlo con éxito.
Requiero que la página que desarrollo haga focus o se ubique en el navegador en la div "textSearch" donde se cargo un php producto de una llamada ajax .
Espero puedan ayudarme, creo necesitar de un ejemplo muy claro debido a mi poca experiencia con JS
gracias, aquí va el código.
Código HTML :
<div id="textSearch"> <input name="textfield" type="text" size="8" onKeyUp="showSearch(this.value); return false"> "aquí también se carga el contenido php que son consultas sin relevancia" </div>
Código Javascript :
///objeto ajax
function objetoAjax(){
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;
}
/// carga archivo php con busqueda
function showSearch(str)
{
if (str.length==0)
{
document.getElementById("txtSearch").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtSearch").innerHTML=xmlhttp.responseText;
}
}
var url = "busqueda_ajax.php?q=" + str;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
