atomicrabbit Posted February 17, 2009 Share Posted February 17, 2009 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 17, 2009 Share Posted February 17, 2009 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> Quote Link to comment Share on other sites More sharing options...
atomicrabbit Posted February 18, 2009 Author Share Posted February 18, 2009 /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. ??? well thanks for the help mjdamato. The few times I've posted here, you always seemed to help. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 18, 2009 Share Posted February 18, 2009 My pleasure. Please make topic as solved! Quote Link to comment Share on other sites More sharing options...
atomicrabbit Posted February 18, 2009 Author Share Posted February 18, 2009 um stupid question... how? ??? edit: nevermind, just saw the link at the bottom. it's kinda hidden. thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.