468,545 Members | 1,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,545 developers. It's quick & easy.

Span with table elements inside table

i all,
I have an HTML table within which I have a span. When the user
clicks a button I want to update the contents of this span with form
elements table elements (TR,TD).

The problem is that if I do not wrap the span tag inside a TR
and TD, it is not properly placed in the table and the update does not
work at all. However if I do place the span inside a TR and TD, the TR
and TD which was supposed to go into the span is not becoming properly
aligned because now I have nested TR and TDs.

Anyone have any thougts, here is some sample code....

function repeatQuestion(divHtml, divId) {
var elem = document.getElementById(divId);
elem.innerHTML = divHtml; // divHtml contains TD and TRs

}

<table>

<span id="divId"></span> // this does not work
<tr><td><span id="divId"></span></td></tr> // this works but format
messed up

<input type=button onClick=repeatQuestion(divHtml,divId)>

</table>

Thanks in advance,
Jehan
Jul 23 '05 #1
2 4954
Falc2199 wrote:
i all,
I have an HTML table within which I have a span. When the user
clicks a button I want to update the contents of this span with form
elements table elements (TR,TD).

The problem is that if I do not wrap the span tag inside a TR
and TD, it is not properly placed in the table and the update does not
work at all. However if I do place the span inside a TR and TD, the TR
and TD which was supposed to go into the span is not becoming properly
aligned because now I have nested TR and TDs.

Anyone have any thougts, here is some sample code....

function repeatQuestion(divHtml, divId) {
var elem = document.getElementById(divId);
elem.innerHTML = divHtml; // divHtml contains TD and TRs

}

<table>

<span id="divId"></span> // this does not work
<tr><td><span id="divId"></span></td></tr> // this works but format
messed up

<input type=button onClick=repeatQuestion(divHtml,divId)>

</table>


Instead of divHtml containing "TD and TR's", have it contain TABLE, TR
and TD tags. Then, you are not inserting fragments of tables, but entire
tables.

Or, use appendChild to add to an existing table.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #2
Ivo
"Falc2199" wrote
I have an HTML table within which I have a span. When the user
clicks a button I want to update the contents of this span with form
elements table elements (TR,TD).

The problem is that if I do not wrap the span tag inside a TR
and TD, it is not properly placed in the table and the update does not
work at all. However if I do place the span inside a TR and TD, the TR
and TD which was supposed to go into the span is not becoming properly
aligned because now I have nested TR and TDs.


Why do you need that span? Replace the (contents of) the TR's and TD's
directly.
The table and its children are very useful elements, but of course you need
to keep them properly nested. That means a TABLE can only contain TR, TBODY,
THEAD and TFOOT elements. A TR can only contain TH and TD elements, but
they can contain all sorts of other elements.
If that is all right, you can easily make use of the rows and cells
collections to access and manipulate whatever you like, even without the
need for unique ID's on each element.
Ivo
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by DMJ | last post: by
2 posts views Thread by Falc2199 | last post: by
4 posts views Thread by blueey | last post: by
27 posts views Thread by Nicholas Couch | last post: by
1 post views Thread by developer | last post: by
5 posts views Thread by Brent | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.