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

<div> tag.innerHTML with table content not working

P: n/a
I have a table (with tabular data) that I want to display on a webpage.
Initially the talbe is empty. When a user clicks on a button, a child
window opens up with a form and some text fields. Then, the user clicks
submit on this child window, closing the child and sending the information
back to the parent.

That part works.

Now, I want to have the parent window change the innerHTML of a div tag that
I have nested in the table like so...

<table>
<div id="someid"></div>
</table>

The idea is, that each time someone clicks submit from one of the children,
the content of the div gets updated... and that works too!!!

But, when I assign it like this:
myVar.innerHTML="<tr><td>data1</td><td>data2</td><td>data3</td></tr>";
the row does not appear in the table, but above it. How can I fix this?

I know I can add <table ....> and </table> to the innerHTML, but I have
column headers that show initially and I would rather avoid having all of
the table created with js.

Any help is greatly appreciated.
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sean wrote:
I have a table (with tabular data) that I want to display on a webpage.
Initially the talbe is empty. When a user clicks on a button, a child
window opens up with a form and some text fields. Then, the user clicks
submit on this child window, closing the child and sending the information
back to the parent. .... But, when I assign it like this:
myVar.innerHTML="<tr><td>data1</td><td>data2</td><td>data3</td></tr>";
the row does not appear in the table, but above it. How can I fix this?


You can't use innerHTML to add rows or cells to a table in IE.
Either use DOM and createElement to add rows & cells, or clone
an existing row and modify the content.
<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/innerhtml.asp>

For browser-neutral, W3C compliant assistance:

<URL:http://www.mozilla.org/docs/dom/technote/tn-dom-table/>

--
Fred
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.