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.

Sorry everyone, I actually solved this in just a few minutes.

The problem was my original select item had a blank value:

<option value="" selected="selected">Building Address</option>

When I assigned a value it worked just fine:

<option value="Building Address" selected="selected">Building Address</option>

This leads me to believe that IE will not accept a "blank" value, which makes me curse Microsoft even more.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.