When I run the code below, Safari's debug console tells me:
TypeError: Result of expression 'document.getElementById("txtHint")' [null] is not an object.
It seems to be throwing the error at this line:
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
Code
function showItem(str)
{
if (str.length==0)
{
document.getElementById("txtHint").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 && xmlhttp.responseText!='')
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getitem.php?q="+str,true);
xmlhttp.send();
}
I am unsure of why this eror is thrown. There is absolutely a DIV with an ID of "txtHint" and yet safari cannot seem to run this code correctly. I guess my question is, what is wrong with this block of code.
ID.console.log(document.getElementById('txtHint').length);say?