I've literally copy and pasted a basic AJAX function from W3 Schools, and for some odd reason it refuses to work on my site...please help.
Here is my HTML:
<select name="address" onChange="sortAddress(this.value)">
<option value="" selected="selected">Building Address</option>
<?php
$sql = "SELECT DISTINCT name FROM buildings ORDER BY location";
$result = mysql_query($sql);
while($r=mysql_fetch_array($result)) {
?>
<option value="<?=$r['name']; ?>"><?=$r['name']; ?></option>
<?php } ?>
</select>
Below is the AJAX I am using.
The bold line errors "Object doesn't support this property or method"
function sortAddress(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
[B] xmlhttp=new XMLHttpRequest();[/B]
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","sort_address.php?q="+str,true);
xmlhttp.send();
}
I am running this function on:
http://bjbproperties.com/index.php?p=residents&s=building_contacts
The page works through a combo box form element. When the user selects the "building", the building information is supposed to display directly below it. Any help is greatly appreciated.