So, I have some AJAX code that dynamically inserts a table of data queried from a database. I assigned each row a unique id so that it can dynamically be edited and updated without having to refresh everything. Everything works fine in Firefox and, of course, it breaks in IE. The following code blows up in IE when it gets to the part where it is setting the innerHTML of the table row equal to value. IE says it has an unknown runtime error. function loadEditWindow(value) { alert(edit_id + 'row'); //for debugging purposes var temp = edit_id + 'row'; //table row id if(value.substring(0,7) == "success") { document.getElementById('editDiv').innerHTML = ""; document.getElementById('editDiv').style.visibility = 'hidden'; document.getElementById(temp).innerHTML = value; //error occurs here document.getElementById( edit_id + 'row').style.backgroundColor = '#9999FF'; editingData = false; } My only theory on what might be wrong is that by dynamically inserting the entire table using the .innerHTML attribute, maybe the objects aren't being added to IE's DOM of the page and so when I try to use getElementById it can't find it. But if that was true it should tell me the object has no properties or something Anyone got any ideas on what IE is yelling about? Or anyone know a good way of debugging javascript in IE? The built in crap isn't helping.
3/5/2008 11:55:19 AM
you can use the IE developer toolbar (kinda like firebug for firefox) to inspect the DOM
3/5/2008 11:59:04 AM
IE has the IE Developer Toolbar you might find useful. It's no firebug, but it's something.[Edited on March 5, 2008 at 12:01 PM. Reason : ^ what he said.]
3/5/2008 12:01:02 PM
sweet, that helps a ton ^, ^^ The elements are in the DOM though, so that shoots down my theory. New theory: IE sucks.****After lots of googling, I think I've figured it out. Apparently in IE innerHTML is read only for certain elements, including TR In other new, Microsoft's documentation website crashes my version of IE, but works in Firefox http://msdn2.microsoft.com/en-us/library/ms533897(VS.85).aspx[Edited on March 5, 2008 at 12:38 PM. Reason : figured it out]
3/5/2008 12:19:57 PM
1) The only reason innerHTML exists is because of IE, so have a little respect.2) This is why one of the fundamental concepts behind AJAX is actually using the DOM.
3/5/2008 6:50:38 PM
3/6/2008 12:27:28 AM
heh, i remember when i first ran into the read-only TR, took me a while to figure that one out tooalso, he means instead of just returning and inserting straight html, you should probably be returning structured XML, parsing it, and creating elements through the DOM method, i.e. using functions like createElement and appendChild and etc.[Edited on March 6, 2008 at 7:48 AM. Reason : document.getElementById(temp).appendChild(document.createElement('td')) and so on]
3/6/2008 7:46:41 AM
3/6/2008 8:26:32 AM
3/6/2008 9:48:46 AM
I see what you're saying, but its really not a requirement that you use XML. I always get a bit miffed at people who act like AJAX is this whole other language in of itself. Its not, its just an acronym made up of a bunch of stuff that already existed. The guy who came up with the acronym was using XML, so he threw that one in there. Also, if you're sending a lot of data like I am, then parsing out the XML and creating a new element for each row and cell is going to be pretty darn slow on the user side. I can't think of any real benefit to always doing it that way, besides maybe that it follows some people's idea of a best practice.
3/6/2008 10:17:07 AM
No one here is acting like it's a whole different language.
3/6/2008 10:54:25 AM
3/6/2008 11:12:37 AM