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

Updating a span inside a table

P: n/a
Hi 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 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Falc2199 wrote:

<table>
<span id="divId"></span> // this does not work
No, it wouldn't. This is invalid HTML. Also there is no content. There
is nothing for the span to affect.
<tr><td><span id="divId"></span></td></tr> // this works but format
messed up
Again, no content.
What layout did you expect? My mindreading skills are weak.
<input type=button onClick=repeatQuestion(divHtml,divId)>
Again, invalid HTML. You cannot put stuff inside a table element that
is not inside a td as well.
</table>

--
jmm dash list at sohnen-moe dot com
(Remove .TRSPAMTR for email)
Jul 20 '05 #2

P: n/a
Falc2199 wrote:
Hi 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


Could you not wrap the rows of the table that you want to change with
<tbody> </tbody> and change its contents?

= Eric

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.