AJAX working in FF, not IE

They have: 222 posts

Joined: Sep 1999

Here's the page: http://apexcommunity.donet.com/?page_id=3. it works in Firefox 1.5.0.4 but not in IE 6. Here's my http object:

function getHTTPObject()
{
if (window.XMLHttpRequest) // Netscape, Mozilla, Firefox, Safari, etc
xmlhttp=new XMLHttpRequest()

else if (window.ActiveXObject) // IE
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")

return xmlhttp;
}

http = new getHTTPObject();
'

I've used that before and it's worked, so I'm not sure what's up. Any ideas?

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

You say it has worked before, are you able to bring up a page using that code in IE and it is workign now? I was reading something in the book I was learning from about in IE you can disbale the ActiveX control needed to do this. Try using another page with this exact function in it in IE now to make sure it STILL works. If so, I doubt it is this function.

-Greg

He has: 1,380 posts

Joined: Feb 2002

Just a small design suggestion...I noticed you have emails written as "whatever at blah dot com"...regular users may not understand this. Why not use an image that is generated with their email address? Search engines / other bots can't pick up the text of this image...it's still "secure" but easy on the eyes.

They have: 222 posts

Joined: Sep 1999

Every time an option in the list is clicked, it's supposed to call the showChurches() JS function. FF is calling it, but I don't think IE is. Here's the code for the list, is there something about it that'd cause IE not to call the function?

<div>
<select name="cities">
<option value="None" onclick="javascript:document.getElementById('show-churches').innerHTML = '';">Choose your city</option>
<option value="Beavercreek" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Beavercreek')">Beavercreek</option>
<option value="Cedarville" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Cedarville')">Cedarville</option>
<option value="Centerville" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Centerville')">Centerville</option>
<option value="Dayton" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Dayton')">Dayton</option>
<option value="Fairborn" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Fairborn')">Fairborn</option>
<option value="Kettering" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Kettering')">Kettering</option>
<option value="Miami Township" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Miami Township')">Miami Township</option>
<option value="Miamisburg" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Miamisburg')">Miamisburg</option>
<option value="Oakwood" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Oakwood')">Oakwood</option>
<option value="Springboro" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Springboro')">Springboro</option>
<option value="Waynesville" onclick="showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=Waynesville')">Waynesville</option>
</select>
</div>
'

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Not sure if this is making the difference, but in your first option, you have:

onclick="javascript:document.getElementById('show-churches').innerHTML = '';"

you don't need the javascript: at the begining, maybe this is choking up IE.

Also, at the very beginning of the showChurches() function, try placing a simple alert() call to test to see if the function itself is being called. Keep moving the alert around to find where the code is flowing to and/or what variable values are at certain points.. It is a crude way of debugging, but it works.

-Greg

They have: 222 posts

Joined: Sep 1999

I do have an alert() in there as the very first statement inside the function, that's why I don't think the function is being called. I removed the javascript: bit but IE still isn't working.

They have: 222 posts

Joined: Sep 1999

Ok, to make debugging easier I changed the function call to alert(), but that's still not working.

Here's the function that is generating the output on that page

<?php
function showHouseChurches()
{   
    global
$wpdb;
   
   
$cities = $wpdb->get_results(\"SELECT DISTINCT churchCity FROM $wpdb->house_churches ORDER BY churchCity ASC\");

    if(count(
$cities) == 0)
        echo 'There are no churches in the directory';
    else
    {
        echo '<div><select name=\"cities\">' . chr(10);
        echo '<option value=\"None\" onclick=\"document.getElementById(\'show-churches\').innerHTML = \'\';\">Choose your city</option>' . chr(10);
        foreach(
$cities as $city)
            printf('<option value=\"%s\" onclick=\"alert(\'%s\')\">%s</option>%s',
$city->churchCity, \"/wp-content/plugins/manage-house-churches/get-church.php?city=\" . $city->churchCity, $city->churchCity, chr(13));
        echo '</select></div>';

        echo '<div id=\"show-churches\"></div>';
    }
}
?>

And here's the actual output

<div>
<select name="cities">
<option value="None" onclick="document.getElementById('show-churches').innerHTML = '';">Choose your city</option><br />
<option value="Beavercreek" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Beavercreek')">Beavercreek</option><br />
<option value="Cedarville" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Cedarville')">Cedarville</option><br />
<option value="Centerville" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Centerville')">Centerville</option><br />
<option value="Dayton" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Dayton')">Dayton</option><br />
<option value="Fairborn" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Fairborn')">Fairborn</option><br />
<option value="Kettering" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Kettering')">Kettering</option><br />
<option value="Miami Township" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Miami Township')">Miami Township</option><br />
<option value="Miamisburg" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Miamisburg')">Miamisburg</option><br />
<option value="Oakwood" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Oakwood')">Oakwood</option><br />
<option value="Springboro" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Springboro')">Springboro</option><br />
<option value="Waynesville" onclick="alert('/wp-content/plugins/manage-house-churches/get-church.php?city=Waynesville')">Waynesville</option><br />
</select>
</div>
'

Every time you click on an option in the list it should do a JavaScript alert(). The code looks fine, and Firefox works fine, but IE doesn't do anything.

Is there anything in IE similiar to FF's Javascript Console so I can see why IE is having problems?

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

It looks like IE doesnt support onclick in individual 's.

I just happened on a site yesterday that had dropdowns to change data like it looks like you are anting to do and in looking at its code, they have the code on the . The following should work, get rid of all the onlicksand change the select to be:
<select name="cities" onChange="selChurches(this);">'

function selChurches(sel)
{
    id = sel.options[sel.selectedIndex].value;
    showChurches('/wp-content/plugins/manage-house-churches/get-church.php?city=' + id);
}
'

-Greg

They have: 222 posts

Joined: Sep 1999

Thank was the problem, thanks Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.