Jump to content

[SOLVED] innerHTML doesn't work in IE after refresh...


atomicrabbit

Recommended Posts

ok I'm racking my brains trying to figure out why my javascript code doesn't work in IE. It works perfectly in the other major browsers, EXCEPT IE. I've tested it in Firefox, and Google Chrome and it works fine in those.

 

the code is basic. There is a simple if statements and obj.innerHTML = "whatever"; This is a small clip of my code where it seems to be fudging. The html is loaded via a PHP file.

 

HTML snippet via dynamic php file:

<td align="center" valign="middle" id="showcase1" style="width:150px;height:150px;"><img src="collection_lib/spacer.gif" id="showcase1_img" alt="" width="150" height="150" border="0" /></td>

 

Javascript (this isn't the actual javascript, but this is whats screwing up):

alert(document.getElementById('showcase1').innerHTML);

 

if I clear the cache and load the page, it pops up a msg box with the following in it:

<img src="collection_lib/spacer.gif" id="showcase1_img" alt="" width="150" height="150" border="0" />

which is what it SHOULD do.

 

but if I reload the page, it pops up a msg box with "null" or doesn't pop up any msg box at all and displays an error in the statusbar saying "object required". This happens in both IE 6 and 7. I checked the source code and 'showcase1' id exists in the page... why is this happening??

 

again, if I clear IE's temporary files and reload the page, it works fine again >:(

Link to comment
Share on other sites

I took the code you posted above and made a test page. Works fine in IE7. Must be something else that is causing the problem.

 

<html>
<head>

<script type="text/javascript">
window.onload = function ()
{
    alert(document.getElementById('showcase1').innerHTML);
}
</script>

</head>
<body>
<table><tr>

<td align="center" valign="middle" id="showcase1" style="width:150px;height:150px;"><img src="collection_lib/spacer.gif" id="showcase1_img" alt="" width="150" height="150" border="0" /></td>

</tr></table>
</body>
</html>

Link to comment
Share on other sites

/facepalm

 

 

 

 

 

 

 

 

 

 

 

it was the stupid window.onload = function () {} ... I wasn't using it. As soon as I put it in, it worked perfectly. I guess when the javascript was running, the html wasn't fully loaded yet. ??? :P

 

well thanks for the help mjdamato. The few times I've posted here, you always seemed to help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.