By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

insertRow madness

P: n/a
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.

--
Hal Burgiss

Jan 9 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hal Burgiss wrote:
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.

--
Rob
Jan 9 '06 #2

P: n/a
On Mon, 09 Jan 2006 04:14:09 GMT, RobG <rg***@iinet.net.au> wrote:
Any help is appreciated.
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!!

--
Hal Burgiss

Jan 9 '06 #3

P: n/a
Hal Burgiss wrote:
On Mon, 09 Jan 2006 04:14:09 GMT, RobG <rg***@iinet.net.au> wrote:

Any help is appreciated.


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().


Ok, cop this. Comment out the line:

document.getElementById('title').innerHTML = my_title;
and see what happens... :-x

--
Rob
Jan 9 '06 #4

P: n/a
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/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp>

Somewhat bizarre side-effect, eh? ;-p

--
Rob
Jan 9 '06 #5

P: n/a
On Mon, 09 Jan 2006 05:18:21 GMT, RobG <rg***@iinet.net.au> wrote:

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

--
Hal Burgiss

Jan 9 '06 #6

P: n/a
On Mon, 09 Jan 2006 05:24:28 GMT, RobG <rg***@iinet.net.au> wrote:

"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?

--
Hal Burgiss

Jan 9 '06 #7

P: n/a
On 9 Jan 2006 06:49:52 -0500, Hal Burgiss <ha*@burgiss.net> wrote:

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.

--
Hal Burgiss

Jan 9 '06 #8

P: n/a
Hal Burgiss wrote:
On Mon, 09 Jan 2006 05:24:28 GMT, RobG <rg***@iinet.net.au> wrote:
"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?


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...
--
Rob
Jan 9 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.