...

View Full Version : Object not found in Internet Explorer



tosbourn
10-09-2008, 12:31 PM
When I run the following code in FF it works fine, but when I run in IE the process completes but the end image doesn't update, when I debug I get an object not found error (although, clearly the object is there or else FF would not work either!).


function ajaxFunction($todo,$status)
{
var xmlHttp;
try
{// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{// Internet Explorer
try
{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch (e)
{
try
{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch (e)
{alert("Your browser does not support AJAX!");return false; }
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
if("mood" == $todo){document.MoodImg.src="style/"+xmlHttp.responseText+".png";}

}
}
if("mood" == $todo){xmlHttp.open("GET","change.php?type=mood",true);}

xmlHttp.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
xmlHttp.send(null);
}

And the object is found...


<div id="MoodIcon">
<img id="MoodImg" src="style/<?PHP echo $mood; ?>.png" /><a onclick="ajaxFunction('mood','');">Change Mood</a>
</div>

The change.php file does its job correctly and contains no JS.

A1ien51
10-09-2008, 02:47 PM
The correct way to reference an object with an id is:

document.getElementById("elementID")

I am sure FF is giving you a warning about bad syntax.

Eric

tosbourn
10-09-2008, 04:05 PM
Gah! You are right (although I must have error reporting turned off on FF)

Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum