insertRow madness

H

Hal Burgiss

Hi, and help for a novice trying to get some data dynamically into
tables. I did a small proof of concept page which works fine in IE6 and
Mozilla. Using code such as this:

tbody = document.getElementById('tb');
thead = document.getElementById('header');

tr = thead.insertRow(-1);
td = document.createElement('th');
tr.appendChild(td);

/* start building data here */

[...]

All is well. I paste essentially the same code with subsequent
modifications below this point into a more complex page and it breaks on
IE6 with a 'null is null and not an object' error, regardless of how I
play with it. It breaks at the insertRow statement. I've tried going to
createElement in lieu of insertRow and it breaks in exactly the same
place. No matter what I change. I've tried inserting into the table
itself, thead, and tbody. All get a null object. And yet the original
page works fine, with nearly identical code! Ouch, my brain hurts.

The test pages are:

http://burgiss.net/work/table.html (works fine)
http://burgiss.net/work/pricelist.html (breaks)

Any help is appreciated.
 
R

RobG

Hal said:
Hi, and help for a novice trying to get some data dynamically into
tables. I did a small proof of concept page which works fine in IE6 and
Mozilla. Using code such as this:

tbody = document.getElementById('tb');
thead = document.getElementById('header');

tr = thead.insertRow(-1);
td = document.createElement('th');
tr.appendChild(td);

/* start building data here */

[...]

All is well. I paste essentially the same code with subsequent
modifications below this point into a more complex page and it breaks on
IE6 with a 'null is null and not an object' error, regardless of how I
play with it. It breaks at the insertRow statement. I've tried going to
createElement in lieu of insertRow and it breaks in exactly the same
place. No matter what I change. I've tried inserting into the table
itself, thead, and tbody. All get a null object. And yet the original
page works fine, with nearly identical code! Ouch, my brain hurts.

The test pages are:

http://burgiss.net/work/table.html (works fine)
http://burgiss.net/work/pricelist.html (breaks)

Any help is appreciated.

Most probably because you have already created thead as a global
variable in drawTable() before makeTable() is called.

Make it local in drawTable() and see what happens.
 
H

Hal Burgiss

Most probably because you have already created thead as a global
variable in drawTable() before makeTable() is called.

Wow, thanks. Looked at it for two hours but did not see that.
Make it local in drawTable() and see what happens.

Sadly, making it a local has not helped yet. I even took out
drawTable() completely and get that error just with makeTable().

Thanks for the help!!
 
R

RobG

Hal said:
Wow, thanks. Looked at it for two hours but did not see that.




Sadly, making it a local has not helped yet. I even took out
drawTable() completely and get that error just with makeTable().

Ok, cop this. Comment out the line:

document.getElementById('title').innerHTML = my_title;


and see what happens... :-x
 
R

RobG

RobG wrote:
[...]
Ok, cop this. Comment out the line:

document.getElementById('title').innerHTML = my_title;


and see what happens... :-x

From the MSDN innerHTML reference:

"The property is read/write for all objects except the following, for
which it is read-only: COL, COLGROUP, FRAMESET, HTML, STYLE, TABLE,
TBODY, TFOOT, THEAD, TITLE, TR. The property has no default value.

...

"You can change the value of the title element using the
document.title property."

<URL:http://msdn.microsoft.com/library/d...hor/dhtml/reference/dhtml_reference_entry.asp>



Somewhat bizarre side-effect, eh? ;-p
 
H

Hal Burgiss

Ok, cop this. Comment out the line:

document.getElementById('title').innerHTML = my_title;


and see what happens... :-x

Hey, wow that was it!!! Amazing. Mucho gracias! I feel a tremendous
weight has been lifted :0
 
H

Hal Burgiss

"You can change the value of the title element using the
document.title property."

Somewhat bizarre side-effect, eh? ;-p

Amen. Now just how did you figure that out?
 
H

Hal Burgiss

Hey, wow that was it!!! Amazing. Mucho gracias! I feel a tremendous
weight has been lifted :0

Even stranger (at least to me), "title" was the id of an h2 element.
Chaning the id to "foo" has the same effect. Wierd. Thanks again though.
 
R

RobG

Hal said:
Amen. Now just how did you figure that out?

thead was an object, but totally bereft of properties. I kept
checking to see when it finally had an ID property.

Remove slabs of stuff until properties appear, then add stuff back
slowly until they're gone again. First I removed all the lines of
makeTable() after the offending line, then the content of the init()
function which gave a clue - fortunately there were only about 6 lines!

No wonder prototyping/RAD is the only way to do web applications -
write a line of code, test everything. Write another line of code,
test everything...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top